|
Project Wonder 5.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecter.extensions.foundation.ERXExpiringCache<K,V>
public class ERXExpiringCache<K,V>
Cache that expires its entries based on time or version changes. Version can be any object that represents the current state of a cached value. When retrieving the value, you can retrieve it with a version key. If the version key used in the retrieval does not match the original version key of the object in the cache, then the cache will invalidate the value for that key and return null. An example version key might be the count of an array, if the count changes, you want to invalidate the cached object. Note that on a time-expiring cache, if you do not use the reaper with startBackgroundExpiration(), or manually call removeStaleEntries(), unexpired entries will remain in the cache for the lifetime of the cache.
Nested Class Summary | |
---|---|
static class |
ERXExpiringCache.Entry<V>
|
protected static class |
ERXExpiringCache.GrimReaper
The reaper runnable for ERXExpiringCache. |
Field Summary | |
---|---|
static long |
NO_TIMEOUT
Designates that no timeout was specified. |
static java.lang.Object |
NO_VERSION
Designates that no explicit version was specified. |
Constructor Summary | |
---|---|
ERXExpiringCache()
Constructs an ERXExpiringCache with a 60 second expiration. |
|
ERXExpiringCache(long expiryTimeInSeconds)
Constructs an ERXExpiringCache with a cleanup time that matches expiryTimeInSeconds. |
|
ERXExpiringCache(long expiryTimeInSeconds,
long cleanupPauseInSeconds)
|
Method Summary | |
---|---|
com.webobjects.foundation.NSArray<K> |
allKeys()
Returns all keys. |
protected ERXExpiringCache.Entry<V> |
entryForKey(K key)
|
boolean |
isStale(K key)
Returns whether or not the object for the given key is a stale cache entry. |
boolean |
isStaleWithVersion(K key,
java.lang.Object currentVersionKey)
Returns whether or not the object for the given key is a stale cache entry given the context of the current version of the key. |
V |
objectForKey(K key)
Returns the value of the given key with an unspecified version. |
V |
objectForKeyWithVersion(K key,
java.lang.Object currentVersionKey)
Returns the value of the given key passing in the current version of the cache value. |
protected static ERXExpiringCache.GrimReaper |
reaper()
Returns the repear for all ERXExpringCaches. |
void |
removeAllObjects()
Removes all the objects in this cache. |
protected void |
removeEntryForKey(ERXExpiringCache.Entry<V> entry,
K key)
|
V |
removeObjectForKey(K key)
Removes the object for the given key. |
void |
removeStaleEntries()
Removes all stale entries. |
protected void |
setEntryForKey(ERXExpiringCache.Entry<V> entry,
K key)
|
void |
setObjectForKey(V object,
K key)
Sets the object for the specified key in this cache with no version specified. |
void |
setObjectForKeyWithVersion(V object,
K key,
java.lang.Object currentVersionKey)
Sets the object for the specified key and current version key. |
void |
setObjectForKeyWithVersion(V object,
K key,
java.lang.Object currentVersionKey,
long expirationTime)
Sets the object for the specified key and current version key. |
void |
startBackgroundExpiration()
Adds this cache to the background thread that reaps time-expired entries from expiring caches. |
void |
stopBackgroundExpiration()
Stops the background reaper for this cache. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long NO_TIMEOUT
public static final java.lang.Object NO_VERSION
Constructor Detail |
---|
public ERXExpiringCache()
public ERXExpiringCache(long expiryTimeInSeconds)
expiryTimeInSeconds
- the lifetime in seconds of an object in the cache or
NO_TIMEOUTpublic ERXExpiringCache(long expiryTimeInSeconds, long cleanupPauseInSeconds)
expiryTimeInSeconds
- the lifetime in seconds of an object in the cache or
NO_TIMEOUTcleanupPauseInSeconds
- the number of seconds to pause between cleanupsMethod Detail |
---|
public void removeAllObjects()
public void setObjectForKey(V object, K key)
object
- the value to setkey
- the lookup keypublic void setObjectForKeyWithVersion(V object, K key, java.lang.Object currentVersionKey, long expirationTime)
object
- the object to setkey
- the lookup keycurrentVersionKey
- the version of the object right nowpublic void setObjectForKeyWithVersion(V object, K key, java.lang.Object currentVersionKey)
object
- the object to setkey
- the lookup keycurrentVersionKey
- the version of the object right nowpublic V objectForKey(K key)
key
- the key to lookup with
public V objectForKeyWithVersion(K key, java.lang.Object currentVersionKey)
key
- the key to lookup withcurrentVersionKey
- the current version of this key
public boolean isStale(K key)
key
- the key to lookup
public boolean isStaleWithVersion(K key, java.lang.Object currentVersionKey)
key
- the key to lookupcurrentVersionKey
- the current version of this key
public V removeObjectForKey(K key)
key
- the key to remove
public void removeStaleEntries()
protected void removeEntryForKey(ERXExpiringCache.Entry<V> entry, K key)
protected void setEntryForKey(ERXExpiringCache.Entry<V> entry, K key)
protected ERXExpiringCache.Entry<V> entryForKey(K key)
public java.lang.String toString()
toString
in class java.lang.Object
public void startBackgroundExpiration()
public void stopBackgroundExpiration()
protected static ERXExpiringCache.GrimReaper reaper()
public com.webobjects.foundation.NSArray<K> allKeys()
|
Last updated: Tue, Feb 21, 2017 05:45 PM CET | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |