org.sandev.basics.util
Interface IDCache

All Known Implementing Classes:
IDCacheBase, NamedSingletonIDCache, NodeLocalIDCache, SingletonIDCache

public interface IDCache

Defines a reliable and efficient lookup of a persistent object instance via its unique identifier. An IDCache works like a local hashtable of global instance data.

It is recommended, but not required, that an IDCache implementation provide a default no-args constructor. Other ctors may take additional parameters to provide for size limits to be enforced during calls to the putInstance method, or to automatically handle proactive updates.

See Persist.html in the top level docs for overview information on caching.


Method Summary
 void clear()
          Remove all entries from this cache.
 SandPersistMessage getInstance(long id)
          Given a persistent ID, return the associated message instance.
 java.util.Map getMap()
          Return the underlying map used by the cache.
 boolean putInstance(SandPersistMessage msg)
          Given a persistent messsage, store it in the cache.
 SandPersistMessage removeInstance(long id)
          Given a persistent ID, remove it from the cache.
 

Method Detail

putInstance

public boolean putInstance(SandPersistMessage msg)
Given a persistent messsage, store it in the cache. Returns true if the cached instance was replaced or added. Returns false if the instance already exists but was not replaced.


getInstance

public SandPersistMessage getInstance(long id)
Given a persistent ID, return the associated message instance. Return null if the instance cannot be retrieved.


removeInstance

public SandPersistMessage removeInstance(long id)
Given a persistent ID, remove it from the cache. Return null if the instance cannot be retrieved.


clear

public void clear()
Remove all entries from this cache.


getMap

public java.util.Map getMap()
Return the underlying map used by the cache. Since this returns a live reference to the map, manipulating the map directly can invalidate or corrupt the contents of the cache. Generally the putInstance(org.sandev.basics.structs.SandPersistMessage) and removeInstance(long) methods should be used for cache manipulation, and this method should only be used for read-only access like iteration over the map's contents.

If the IDCache is not backed by a map, returns null.