02/28/2005
 

com.vignette.portal.cache
Class SizeBasedStrategy

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

public abstract class SizeBasedStrategy
extends ActionBasedCacheStrategy

Keeps the number of entries in the cache below a given threshold. It removes elements when it detects that the size limit is being exceeded. Subclasses implement specific algorithms for selecting which elements to onRemove and when to check the size boundary.


Constructor Summary
SizeBasedStrategy(CacheAction action, int sizeOfCache)
          Creates a cache of specified size with specified action logic.
SizeBasedStrategy(int sizeOfCache)
          Creates a cache of specified size with default action logic.
 
Method Summary
protected  int getSizeOfCache()
           
 void onInvalidate(Object key)
          Someone wants to remove key from the cache.
 void onInvalidateAll()
          Someone wants to remove all keys from the cache.
 void onInvalidateAll(Collection keys)
          Someone wants to remove keys from the cache.
 void onRemove(Object key)
          Signals removal from the cache.
 void onRemoveAll()
          Signals clearing of the cache.
 void onRemoveAll(Collection keys)
          Signals removals from the cache.
 
Methods inherited from class com.vignette.portal.cache.ActionBasedCacheStrategy
getCacheAction, setStore
 
Methods inherited from class com.vignette.portal.cache.CacheStrategy
getStore, onAdd, onAddAll, onGet, onGetAll, onPut, onPutAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SizeBasedStrategy

public SizeBasedStrategy(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:
ActionBasedCacheStrategy.ActionBasedCacheStrategy()

SizeBasedStrategy

public SizeBasedStrategy(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:
ActionBasedCacheStrategy.ActionBasedCacheStrategy(CacheAction)
Method Detail

getSizeOfCache

protected int getSizeOfCache()

onInvalidate

public void onInvalidate(Object key)
                  throws CacheException
Description copied from class: CacheStrategy

Someone wants to remove key from the cache. This strategy can reject the operation by throwing an exception. The actual removal, if allowed, will be signalled later by a call to this strategy's onRemove method.

Overrides:
onInvalidate in class CacheStrategy
Following copied from class: com.vignette.portal.cache.CacheStrategy
Parameters:
key - key being removed

onInvalidateAll

public void onInvalidateAll(Collection keys)
                     throws CacheException
Description copied from class: CacheStrategy

Someone wants to remove keys from the cache. This strategy can reject the operation by throwing an exception. The actual removal, if allowed, will be signalled later by a call to this strategy's onRemoveAll method.

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

Overrides:
onInvalidateAll in class CacheStrategy
Following copied from class: com.vignette.portal.cache.CacheStrategy
Parameters:
keys - keys being removed

onInvalidateAll

public void onInvalidateAll()
                     throws CacheException
Description copied from class: CacheStrategy

Someone wants to remove all keys from the cache. This strategy can reject the operation by throwing an exception. The actual removal, if allowed, will be signalled later by a call to this strategy's onRemoveAll method.

Overrides:
onInvalidateAll in class CacheStrategy

onRemove

public void onRemove(Object key)
Description copied from class: CacheStrategy

Signals removal from the cache. The mapping for key is being removed from the cache and this strategy should stop monitoring it and clean up, if appropriate for its algorithm.

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 onInvalidate instead. But note that another strategy could call this method without calling onInvalidate first, in which case there is no way to recover from invalid conditions.

Overrides:
onRemove in class CacheStrategy
Following copied from class: com.vignette.portal.cache.CacheStrategy
Parameters:
key - key being removed from the cache

onRemoveAll

public void onRemoveAll(Collection keys)
Description copied from class: CacheStrategy

Signals removals from the cache. The mapping for keys are being removed from the cache and this strategy should stop monitoring them and clean up, if appropriate for its algorithm.

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 onInvalidateAll instead. But note that another strategy could call this method without calling onInvalidateAll 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.onRemoveAll(Collection).

Overrides:
onRemoveAll in class CacheStrategy
Following copied from class: com.vignette.portal.cache.CacheStrategy
Parameters:
keys - keys being removed from the cache

onRemoveAll

public void onRemoveAll()
Description copied from class: CacheStrategy

Signals clearing of the cache. All mappings for all keys are being removed from the cache and this strategy should stop monitoring any of them and clean up, if appropriate for its algorithm.

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 onInvalidateAll instead. But note that another strategy could call this method without calling onInvalidateAll first, in which case there is no way to recover from invalid conditions.

Overrides:
onRemoveAll in class CacheStrategy

02/28/2005
 

Copyright and Trademark Notices