Ehcache 1.5.0 User Guide - Cache Eviction Algorithms (缓存移出算法)

 

Ehcache 1.5.0 User Guide -  Cache Eviction Algorithms (缓存移出算法)

Ehcache 1.5.0 用户指南)

E_mail:jianglike18@163.con

Blog: http://blog.csdn.net/jianglike18

qq:29396597

7Cache Eviction Algorithms (缓存移出算法)

7.1 Eviction(逐出/收回)

A cache eviction algorithm is a way of deciding which Element to evict when the cache is full.

(缓存的收回算法是一种当缓存满了决定哪一个元素移出的方法。)

 

In ehcache the MemoryStore has a fixed limited size set by maxElementsInMemory. When the store gets full, elements are evicted. The eviction algorithms in ehcache determines which elements is evicted. The default is LRU.

(在ehcache中,MemoryStore(内存存储)通过属性maxElementsInMemory限制了内存使用的大小。当存储空间满的时候,元素将被移出。Ehcache中的移出算法决定什么对象被移出,。默认是使用LRU算法。)

 

What happens on eviction depends on the cache configuration. If a DiskStore is configured, the evicted element will overflow to disk, otherwise it will be removed.

(移出的怎么办依赖月缓存的配置。如果DiskStore(磁盘存储) 被指定,那么对象会被写入磁盘,否则对象被删除。)

 

The DiskStore size by default is unbounded. But a maximum size can be set using the maxElementsOnDisk cache attribute. If the DiskStore is full, then adding an element will cause one to be evicted. The DiskStore eviction algorithm is not configurable. It uses LFU.

DiskStore大小默认为无穷大。但是最大值可以用缓存的maxElementsOnDisk属性指定。如果DiskStore满了,添加一个对象会导致一个对象被移出磁盘。DiskStore的移出策略是不可配的。使用的是LFU。)

 

7.1.1 Supported MemoryStore Eviction Algorithms(可支持的内存回收算法)

The idea here is, given a limit on the number of items to cache, how to choose the thing to evict that gives the best result.

(这里的意思是说给出一个缓存对象数量的限制,如果选择被移出的对象才能得到最好的结果。)

 

In 1966 Laszlo Belady showed that the most efficient caching algorithm would be to always discard the information that will not be needed for the longest time in the future. This it a theoretical result that is unimplementable without domain knowledge. The Least Recently Used ("LRU") algorithm is often used as a proxy. It works pretty well because of the locality of reference phenonemon. As a result, LRU is the default eviction algorithm in ehcache, as it is in most caches.

1996Laszlo Belady指出最有效的缓存算法是总是丢弃将来很长一段时间内都不会使用的信息。这只是一个理论结果,在领域外没有真正的实现。最近最少使用("LRU")算法是一种常用的策略。因为相关类型的位置,它非常有效。因此,LRUehcache默认的移出算法,也在大部分缓存中使用。)

 

Ehcache users may sometimes have a good domain knowledge. Accordingly, ehcache provides three eviction algorithms to choose from for the MemoryStore.

ehcache的使用者有时拥有很好的领域知识。因此,ehcache为内存存储提供了三种移出的算法供选择)

7.1.2 MemoryStore Eviction Algorithms(内存存储移出算法)

The MemoryStore supports three eviction algorithms: LRU, LFU and FIFO.

The default is LRU.

(内存存储支持三种移出算法:LRU,LFUFIFO。默认的LRU

 

7.1.2.1 Least Recently Used (LRU) (最近最久被使用(LRU)

The eldest element, is the Least Recently Used (LRU). The last used timestamp is updated when an element is put into the cache or an element is from the cache with retrieved a get call.

(最久的对象,是最近最少使用的(LRU.当一个对象被放入缓存或通过调用get方法时,最近使用的时间戳将被更新。)

 

7.1.2.2 Less Frequently Used (LFU)(最近最不常使用(LFU))

For each get call on the element the number of hits is updated. When a put call is made for a new element (and assuming that the max limit is reached) the element with least number of hits, the Less Frequently Used element, is evicted.

(每一次获取对象的调用,该对象的命中次数都会更新。当为一个新对象调用put(假定已经到了最大对象的限制),最少命中的对象,最少使用的对象被移出。)

 

If cache element use follows a pareto distribution, this algorithm may give better results than LRU.LFU is an algorithm unique to ehcache. It takes a random sample of the Elements and evicts the smallest. Using the sample size of 30 elements, empirical testing shows that an Element in the lowest quartile of use is evicted 99.99% of the time.

如果缓存元素使用后Pareto分布, 这个算法可以给出比LRU算法更好的结果。LFUehcache一个独特的算法。获取一些随机对象的例子并移出最少使用的。使用为30个对象例子,经验主义测试显示最低使用的对象99.99%的时间是被移出。)

 

7.1.2.3 First In First Out (FIFO)(先进先出)

Elements are evicted in the same order as they come in. When a put call is made for a new element (and assuming that the max limit is reached for the memory store) the element that was placed first (First-In) in the store is the candidate for eviction (First-Out).

This algorithm is used if the use of an element makes it less likely to be used in the future. An example here would be an authentication cache.

(对象按照其进来的次序被移出对象。当为一个新对象调用put(假定已经到了最大对象的限制),内存中最先进入的对象最先被移出。如果使用了的对象将来很少被使用的情况,可以使用该算法。这有一个简单的例子就是权限验证的缓存。)

 

7.1.3 DiskStore Eviction Algorithms(磁盘移出算法)

The DiskStore uses the Less Frequently Used algorithm to evict an element when it is full.

(当磁盘存储满了,使用最近最不常用算法来移出对象。)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值