02/28/2005
 

com.vignette.portal.cache
Class LeastRecentlyUsedStrategy

java.lang.Object
  |
  +--com.vignette.portal.cache.CacheStrategy
        |
        +--com.vignette.portal.cache.ActionBasedCacheStrategy
              |
              +--com.vignette.portal.cache.SizeBasedStrategy
                    |
                    +--com.vignette.portal.cache.LeastRecentlyUsedStrategy

public abstract class LeastRecentlyUsedStrategy
extends SizeBasedStrategy

Removes the least recently used entries from the cache when the cache's size is being exceeded. This algorithm relies on locality of access to data.

This principle states that a given group of data is either used together or not at all at any given point in time. As you request a piece of data, your next request is very likely to be either for it again, or one of the pieces you requested just prior to it. Therefore, the likelihood of reuse of a piece of data diminishes the further back in time you last accessed it.

This strategy must record the access pattern for all keys and therefore incurs overhead on every call to the cache, thereby reducing its performance.


Constructor Summary
LeastRecentlyUsedStrategy(CacheAction action, int sizeOfCache)
          Creates a cache of specified size with specified action logic.
LeastRecentlyUsedStrategy(int sizeOfCache)
          Creates a cache of specified size with default action logic.
 
Method Summary
 void onAdd(Object key, Object value, Map properties)
          Signals addition to the cache.
 void onAddAll(Map keyValuePairs, Map properties)
          Signals additions to the cache.
 void onGet(Object key, Map properties)
          Someone is accessing key in the Cache.
protected  void touch(Object key)
          This method should be called when a key is accessed to re-align its usage value.
 
Methods inherited from class com.vignette.portal.cache.SizeBasedStrategy
getSizeOfCache, onInvalidate, onInvalidateAll, onInvalidateAll, onRemove, onRemoveAll, onRemoveAll
 
Methods inherited from class com.vignette.portal.cache.ActionBasedCacheStrategy
getCacheAction, setStore
 
Methods inherited from class com.vignette.portal.cache.CacheStrategy
getStore, onGetAll, onPut, onPutAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeastRecentlyUsedStrategy

public LeastRecentlyUsedStrategy(int sizeOfCache)

Creates a cache of specified size with default action logic.

Parameters:
sizeOfCache - the maximum number of objects allowed in the cache.
See Also:
SizeBasedStrategy.SizeBasedStrategy(int)

LeastRecentlyUsedStrategy

public LeastRecentlyUsedStrategy(CacheAction action,
                                 int sizeOfCache)

Creates a cache of specified size with specified action logic.

Parameters:
action - the non-null action to invoke when the size of the cache is exceeded.
sizeOfCache - the maximum number of objects allowed in the cache.
See Also:
SizeBasedStrategy.SizeBasedStrategy(CacheAction, int)
Method Detail

onGet

public void onGet(Object key,
                  Map properties)
           throws CacheException
Description copied from class: CacheStrategy

Someone is accessing key in the Cache.

Individual strategies can use the information in properties to override their creation-time parameters.

Overrides:
onGet in class CacheStrategy
Following copied from class: com.vignette.portal.cache.CacheStrategy
Parameters:
key - item being looked up
properties - possible overrides, can be null

onAdd

public void onAdd(Object key,
                  Object value,
                  Map properties)
Description copied from class: CacheStrategy

Signals addition to the cache. The mapping of key to value is being inserted in the cache and this strategy should start monitoring it, if appropriate for its algorithm.

Individual strategies can use the information in properties to override their creation-time parameters.

This method should not throw any exception since other strategies on the same cache might already have changed their state in response to this signal and the cache will not be able to revert them back to their prior state. The strategies will become out of sync with each other and with the cache, yielding unpredictable behavior.

Perform any validation checks in onPut instead. But note that another strategy could call this method without calling onPut first, in which case there is no way to recover from invalid conditions.

Overrides:
onAdd in class CacheStrategy
Following copied from class: com.vignette.portal.cache.CacheStrategy
Parameters:
key - key being inserted in the cache
value - value being inserted in the cache, matching key
properties - possible overrides, can be null

onAddAll

public void onAddAll(Map keyValuePairs,
                     Map properties)
Description copied from class: CacheStrategy

Signals additions to the cache. The mappings in keyValuePairs are being inserted in the cache and this strategy should start monitoring them, if appropriate for its algorithm.

Individual strategies can use the information in properties to override their creation-time parameters.

This method should not throw any exception since other strategies on the same cache might already have changed their state in response to this signal and the cache will not be able to revert them back to their prior state. The strategies will become out of sync with each other and with the cache, yielding unpredictable behavior.

Perform any validation checks in onPutAll instead. But note that another strategy could call this method without calling onPutAll first, in which case there is no way to recover from invalid conditions.

This is a default implementation. For performance purposes you may wish to override it. If you do, you should not be calling super.onAddAll(Map, Map).

Overrides:
onAddAll in class CacheStrategy
Following copied from class: com.vignette.portal.cache.CacheStrategy
Parameters:
keyValuePairs - key/value pairs being added to the cache
properties - possible overrides, can be null

touch

protected final void touch(Object key)
This method should be called when a key is accessed to re-align its usage value.
Parameters:
key - the key "touched"

02/28/2005
 

Copyright and Trademark Notices