02/28/2005
 

com.vignette.portal.cache
Class TimeBasedStrategy

java.lang.Object
  |
  +--com.vignette.portal.cache.CacheStrategy
        |
        +--com.vignette.portal.cache.ActionBasedCacheStrategy
              |
              +--com.vignette.portal.cache.TimeBasedStrategy
All Implemented Interfaces:
Periodical

public abstract class TimeBasedStrategy
extends ActionBasedCacheStrategy
implements Periodical

Removes entries from the cache after a given amount of time has elapsed. Subclasses implement specific algorithms for measuring the elapsed time.

Callers can provide overrides to the configuration parameters with every call to the cache via an optional Map parameter.

This strategy and its subclasses will look in this map for the key TimeBasedStrategy.getOverrideTimeoutProperty() and an associated value of type Number to use instead of the value passed at constrction time and use it to compute the entry's expiration time.

This strategy and its subclasses will also look in this map for the key TimeBasedStrategy.getNeverExpireProperty() and if present, will not expire the given entry at any time.

This strategy implements the Periodical interface and checks the expiration times as part of its TimeBasedStrategy.onPeriod(long) method. Between periods, nothing gets expired. This means that the expiration time for entries has a resolution that is governed by how often the TimeBasedStrategy.onPeriod(long) method is called, which is beyond the control of the user of this API.


Constructor Summary
TimeBasedStrategy(CacheAction action, long defaultTimeout)
          Creates a cache with specified timeout and with specified action logic.
TimeBasedStrategy(long defaultTimeout)
          Creates a cache with specified timeout and with default action logic.
 
Method Summary
protected  boolean containsKey(Object key)
           
 long getDefaultTimeout()
           
 Object getNeverExpireProperty()
          Get the key to be used for the never expire override property.
 Object getOverrideTimeoutProperty()
          Get the key to be used for the expiration timeout override property.
 void onAdd(Object key, Object value, Map properties)
          Signals addition to the cache.
 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 onPeriod(long now)
           
 void onPut(Object key, Object value, Map properties)
          Someone wants to add the pair key / value to the cache.
 void onPutAll(Map keyValuePairs, Map properties)
          Someone wants to add the pairs in keyValuePairs to 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.
protected  boolean updateExpirationTime(Object key, Map properties)
          Update the expiration time for the key
 
Methods inherited from class com.vignette.portal.cache.ActionBasedCacheStrategy
getCacheAction, setStore
 
Methods inherited from class com.vignette.portal.cache.CacheStrategy
getStore, onAddAll, onGet, onGetAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeBasedStrategy

public TimeBasedStrategy(long defaultTimeout)
                  throws IllegalArgumentException

Creates a cache with specified timeout and with default action logic.

Parameters:
defaultTimeout - the maximum time, in milliseconds, that objects are allowed in the cache.
See Also:
ActionBasedCacheStrategy.ActionBasedCacheStrategy()

TimeBasedStrategy

public TimeBasedStrategy(CacheAction action,
                         long defaultTimeout)
                  throws IllegalArgumentException

Creates a cache with specified timeout and with specified action logic.

Parameters:
action - the non-null action to invoke when the size of the cache is exceeded.
defaultTimeout - the maximum time, in milliseconds, that objects are allowed in the cache.
See Also:
ActionBasedCacheStrategy.ActionBasedCacheStrategy(CacheAction)
Method Detail

getNeverExpireProperty

public final Object getNeverExpireProperty()
Get the key to be used for the never expire override property.

getOverrideTimeoutProperty

public final Object getOverrideTimeoutProperty()
Get the key to be used for the expiration timeout override property.

getDefaultTimeout

public long getDefaultTimeout()

onPut

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

Someone wants to add the pair key / value to the cache. This strategy can reject the operation by throwing an exception. The actual addition, if allowed, will be signalled later by a call to this strategy's onAdd method.

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

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

onPutAll

public void onPutAll(Map keyValuePairs,
                     Map properties)
              throws CacheException
Description copied from class: CacheStrategy

Someone wants to add the pairs in keyValuePairs to the cache. This strategy can reject the operation by throwing an exception. The actual addition, if allowed, will be signalled later by a call to this strategy's onAddAll method.

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

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

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

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

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

updateExpirationTime

protected final boolean updateExpirationTime(Object key,
                                             Map properties)
Update the expiration time for the key
Parameters:
key - the key whose expiration time should be updated
properties - possible override map
Returns:
true if the key is being monitored by the strategy, false otherwise

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

onPeriod

public void onPeriod(long now)
Specified by:
onPeriod in interface Periodical

containsKey

protected final boolean containsKey(Object key)

02/28/2005
 

Copyright and Trademark Notices