jodd.cache
Class LFUCache<K,V>

java.lang.Object
  extended by jodd.cache.AbstractCacheMap<K,V>
      extended by jodd.cache.LFUCache<K,V>
All Implemented Interfaces:
Cache<K,V>

public class LFUCache<K,V>
extends AbstractCacheMap<K,V>

LFU (least frequently used) cache. Frequency is calculated as access count. This cache is resistant on 'new usages scenario': when some object is removed from the cache, access count of all items in cache is decreased by access count of removed value. This allows new frequent elements to come into the cache.

Frequency of use data is kept on all items. The most frequently used items are kept in the cache. Because of the bookkeeping requirements, cache access overhead increases logarithmically with cache size. The advantage is that long term usage patterns are captured well, incidentally making the algorithm scan resistant; the disadvantage, besides the larger access overhead, is that the algorithm doesn't adapt quickly to changing usage patterns, and in particular doesn't help with temporally clustered accesses.

Summary for LFU: not fast, captures frequency of use, scan resistant.


Field Summary
 
Fields inherited from class jodd.cache.AbstractCacheMap
cacheLock, cacheMap, cacheSize, existCustomTimeout, timeout
 
Constructor Summary
LFUCache(int maxSize)
           
LFUCache(int maxSize, long timeout)
           
 
Method Summary
protected  void onRemove(K key, V cachedObject)
          Callback method invoked on cached object removal.
protected  int pruneCache()
          Prunes expired and, if cache is still full, the LFU element(s) from the cache.
 
Methods inherited from class jodd.cache.AbstractCacheMap
clear, get, getCacheSize, getCacheTimeout, isEmpty, isFull, isPruneExpiredActive, iterator, prune, put, put, remove, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LFUCache

public LFUCache(int maxSize)

LFUCache

public LFUCache(int maxSize,
                long timeout)
Method Detail

pruneCache

protected int pruneCache()
Prunes expired and, if cache is still full, the LFU element(s) from the cache. On LFU removal, access count is normalized to value which had removed object. Returns the number of removed objects.

Specified by:
pruneCache in class AbstractCacheMap<K,V>

onRemove

protected void onRemove(K key,
                        V cachedObject)
Callback method invoked on cached object removal. By default does nothing.



Copyright © 2003-2012 Jodd Team