ERXExpiringCache< K, V > Class Reference

Collaboration diagram for ERXExpiringCache< K, V >:

Collaboration graph
[legend]

List of all members.

Classes

class  Entry< V >
class  GrimReaper

Public Member Functions

synchronized NSArray< K > allKeys ()
 ERXExpiringCache (long expiryTimeInSeconds, long cleanupPauseInSeconds)
 ERXExpiringCache (long expiryTimeInSeconds)
 ERXExpiringCache ()
synchronized boolean isStale (K key)
synchronized boolean isStaleWithVersion (K key, Object currentVersionKey)
synchronized V objectForKey (K key)
synchronized V objectForKeyWithVersion (K key, Object currentVersionKey)
synchronized void removeAllObjects ()
synchronized V removeObjectForKey (K key)
synchronized void removeStaleEntries ()
synchronized void setObjectForKey (V object, K key)
synchronized void setObjectForKeyWithVersion (V object, K key, Object currentVersionKey)
synchronized void setObjectForKeyWithVersion (V object, K key, Object currentVersionKey, long expirationTime)
void startBackgroundExpiration ()
synchronized void stopBackgroundExpiration ()
String toString ()

Static Public Attributes

static final long NO_TIMEOUT = 0L
static final Object NO_VERSION = new Object()

Protected Member Functions

synchronized Entry< V > entryForKey (K key)
synchronized void removeEntryForKey (Entry< V > entry, K key)
synchronized void setEntryForKey (Entry< V > entry, K key)

Static Protected Member Functions

static synchronized
ERXExpiringCache.GrimReaper 
reaper ()

Private Member Functions

long expiryTime ()

Private Attributes

NSMutableDictionary< K,
ERXExpiringCache.Entry< V > > 
_backingDictionary
long _cleanupPause
long _expiryTime
long _lastCleanupTime

Static Private Attributes

static ERXExpiringCache.GrimReaper _reaper


Detailed Description

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.

Author:
ak

mschrag


Constructor & Destructor Documentation

ERXExpiringCache (  ) 

Constructs an ERXExpiringCache with a 60 second expiration.

ERXExpiringCache ( long  expiryTimeInSeconds  ) 

Constructs an ERXExpiringCache with a cleanup time that matches expiryTimeInSeconds.

Parameters:
expiryTimeInSeconds the lifetime in seconds of an object in the cache or NO_TIMEOUT

ERXExpiringCache ( long  expiryTimeInSeconds,
long  cleanupPauseInSeconds 
)

Parameters:
expiryTimeInSeconds the lifetime in seconds of an object in the cache or NO_TIMEOUT
cleanupPauseInSeconds the number of seconds to pause between cleanups


Member Function Documentation

synchronized NSArray<K> allKeys (  ) 

Returns all keys.

synchronized Entry<V> entryForKey ( key  )  [protected]

long expiryTime (  )  [private]

synchronized boolean isStale ( key  ) 

Returns whether or not the object for the given key is a stale cache entry.

Parameters:
key the key to lookup
Returns:
true if the value is stale

synchronized boolean isStaleWithVersion ( key,
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.

Parameters:
key the key to lookup
currentVersionKey the current version of this key
Returns:
true if the value is stale

synchronized V objectForKey ( key  ) 

Returns the value of the given key with an unspecified version.

Parameters:
key the key to lookup with
Returns:
the value in the cache or null

synchronized V objectForKeyWithVersion ( key,
Object  currentVersionKey 
)

Returns the value of the given key passing in the current version of the cache value. If the version key passed in does not match the version key in the cache, the cache will invalidate that key.

Parameters:
key the key to lookup with
currentVersionKey the current version of this key
Returns:
the value in the cache or null

static synchronized ERXExpiringCache.GrimReaper reaper (  )  [static, protected]

Returns the repear for all ERXExpringCaches.

Returns:
the repear for all ERXExpringCaches

synchronized void removeAllObjects (  ) 

Removes all the objects in this cache.

synchronized void removeEntryForKey ( Entry< V >  entry,
key 
) [protected]

synchronized V removeObjectForKey ( key  ) 

Removes the object for the given key.

Parameters:
key the key to remove
Returns:
the removed object

synchronized void removeStaleEntries (  ) 

Removes all stale entries.

synchronized void setEntryForKey ( Entry< V >  entry,
key 
) [protected]

synchronized void setObjectForKey ( object,
key 
)

Sets the object for the specified key in this cache with no version specified.

Parameters:
object the value to set
key the lookup key

synchronized void setObjectForKeyWithVersion ( object,
key,
Object  currentVersionKey 
)

Sets the object for the specified key and current version key.

Parameters:
object the object to set
key the lookup key
currentVersionKey the version of the object right now

synchronized void setObjectForKeyWithVersion ( object,
key,
Object  currentVersionKey,
long  expirationTime 
)

Sets the object for the specified key and current version key.

Parameters:
object the object to set
key the lookup key
currentVersionKey the version of the object right now

void startBackgroundExpiration (  ) 

Adds this cache to the background thread that reaps time-expired entries from expiring caches. If this cache is not a time-expiration cache, this will throw an IllegalArgumentException.

synchronized void stopBackgroundExpiration (  ) 

Stops the background reaper for this cache.

String toString (  ) 


Member Data Documentation

NSMutableDictionary<K, ERXExpiringCache.Entry<V> > _backingDictionary [private]

long _cleanupPause [private]

long _expiryTime [private]

long _lastCleanupTime [private]

ERXExpiringCache.GrimReaper _reaper [static, private]

The reaper for ERXExpiringCaches.

final long NO_TIMEOUT = 0L [static]

Designates that no timeout was specified.

final Object NO_VERSION = new Object() [static]

Designates that no explicit version was specified.


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:12 2012 for Project Wonder by  doxygen 1.5.8