org.sandev.basics.util
Class SingletonIDCache

java.lang.Object
  extended by org.sandev.basics.util.IDCacheBase
      extended by org.sandev.basics.util.SingletonIDCache
All Implemented Interfaces:
IDCache

public class SingletonIDCache
extends IDCacheBase
implements IDCache

A singleton IDCache for shared object caching. One cache is instantiated per virtual machine. This is optimal for minimizing the overall memory footprint of the application, and for maximizing the chance that a retrieved object will be found in the cache, but is NOT recommended for multiapp or multiserver development:

WARNING: Nodes sharing access to the same IDCache must have the same security and authorization to avoid retrieving more or less information than what should be there.

To share the same cache across multiple nodes with different authorization, write a "privileged" node to hold the cache, and then have all the client nodes get their info served from the privileged node via Authorizers.


Field Summary
protected static SingletonIDCache cache
          Our singleton reference
 
Fields inherited from class org.sandev.basics.util.IDCacheBase
callback, map, revisionCheck, timeToLiveMillis
 
Constructor Summary
protected SingletonIDCache()
          no access, default ctor.
 
Method Summary
static SingletonIDCache getSingletonIDCache()
          return the singleton reference
protected static void instantiateCache()
          Instantiate the cache.
 
Methods inherited from class org.sandev.basics.util.IDCacheBase
checkRevisionNumber, cleanup, clear, find, getCallback, getInstance, getMap, getSortedItems, getStats, getTimeToLiveMillis, idToKey, init, putInstance, removeInstance, setCallback, setRevisionCheck, setTimeToLiveMillis
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.sandev.basics.util.IDCache
cleanup, clear, find, getCallback, getInstance, getMap, getStats, getTimeToLiveMillis, putInstance, removeInstance, setCallback, setTimeToLiveMillis
 

Field Detail

cache

protected static SingletonIDCache cache
Our singleton reference

Constructor Detail

SingletonIDCache

protected SingletonIDCache()
no access, default ctor. Does nothing.

Method Detail

getSingletonIDCache

public static SingletonIDCache getSingletonIDCache()
return the singleton reference


instantiateCache

protected static void instantiateCache()
Instantiate the cache. Make sure we only do this once. It is possible to have several threads try and instantiate the singleton at once. For a cache, it's important to prevent that from happening so you don't throw away a retrieved instance by accident.

Because of the thread lineup, the initial conditional test is actually necessary.