org.sakaiproject.component.framework.memory
Class MultiRefCacheImpl

java.lang.Object
  extended byorg.sakaiproject.component.framework.memory.MemCache
      extended byorg.sakaiproject.component.framework.memory.MultiRefCacheImpl
All Implemented Interfaces:
Cache, Cacher, MultiRefCache, Observer, Runnable

public class MultiRefCacheImpl
extends MemCache
implements MultiRefCache

MultiRefCacheImpl implements the MultiRefCache.

The references that each cache entry are sensitive to are kept in a separate map for easy access.
Manipulation of this map is synchronized. This map is not used for cache access, just when items are added and removed.
The cache map itself becomes synchronized when it's manipulated (not when reads occur), so this added sync. for the refs fits the existing pattern.

Author:
Sakai Software Development Team

Nested Class Summary
protected  class MultiRefCacheImpl.MultiRefCacheEntry
           
 
Nested classes inherited from class org.sakaiproject.component.framework.memory.MemCache
MemCache.CacheEntry
 
Field Summary
protected  Map m_refs
          Map of reference string -> Collection of cache keys.
 
Fields inherited from class org.sakaiproject.component.framework.memory.MemCache
m_complete, m_disabled, m_eventTrackingService, m_getCount, m_heldEvents, m_hitCount, m_holdEventProcessing, m_logger, m_map, m_memoryService, m_partiallyComplete, m_putCount, m_refresher, m_refresherSleep, m_resourcePattern, m_softRefs, m_thread, m_threadStop
 
Constructor Summary
MultiRefCacheImpl(BasicMemoryService memoryService, EventTrackingService eventTrackingService, Logger logger, long sleep)
          Construct the Cache - checks for expiration periodically.
 
Method Summary
protected  void addRefCachedKey(String ref, Object key)
          Make sure there's an entry in refs for this ref that includes this key.
 void clear()
          Clear all entries.
protected  void continueUpdate(Event event)
          Complete the update, given an event that we know we need to act upon.
 String getDescription()
          Return a description of the cacher.
 boolean isComplete()
          Are we complete?
 boolean isComplete(String path)
          Are we complete for one level of the reference hierarchy?
 void put(Object key, Object payload)
          Cache an object - don't automatically exipire it.
 void put(Object key, Object payload, int duration)
          Cache an object
 void put(Object key, Object payload, int duration, String ref, Collection azgIds)
          Cache an object
 void remove(Object key)
          Remove this entry from the cache.
 void update(Observable o, Object arg)
          This method is called whenever the observed object is changed.
 
Methods inherited from class org.sakaiproject.component.framework.memory.MemCache
containsKey, containsKeyExpiredOrNot, destroy, disable, disabled, enable, expire, get, getAll, getAll, getExpiredOrNot, getIds, getKeys, getSize, holdEvents, processEvents, referencePath, resetCache, run, setComplete, setComplete, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.sakaiproject.service.framework.memory.Cache
containsKey, containsKeyExpiredOrNot, destroy, disable, disabled, enable, expire, get, getAll, getAll, getExpiredOrNot, getIds, getKeys, holdEvents, processEvents, setComplete, setComplete
 
Methods inherited from interface org.sakaiproject.service.framework.memory.Cacher
getSize, resetCache
 

Field Detail

m_refs

protected Map m_refs
Map of reference string -> Collection of cache keys.

Constructor Detail

MultiRefCacheImpl

public MultiRefCacheImpl(BasicMemoryService memoryService,
                         EventTrackingService eventTrackingService,
                         Logger logger,
                         long sleep)
Construct the Cache - checks for expiration periodically.

Method Detail

put

public void put(Object key,
                Object payload,
                int duration,
                String ref,
                Collection azgIds)
Description copied from interface: MultiRefCache
Cache an object

Specified by:
put in interface MultiRefCache
Parameters:
key - The key with which to find the object.
payload - The object to cache.
duration - The time to cache the object (seconds).
ref - One entity reference that, if changed, will invalidate this entry.
azgIds - AuthzGroup ids that, if the changed, will invalidate this entry.

put

public void put(Object key,
                Object payload,
                int duration)
Description copied from interface: Cache
Cache an object

Specified by:
put in interface Cache
Overrides:
put in class MemCache
Parameters:
key - The key with which to find the object.
payload - The object to cache.
duration - The time to cache the object (seconds).

put

public void put(Object key,
                Object payload)
Description copied from interface: Cache
Cache an object - don't automatically exipire it.

Specified by:
put in interface Cache
Overrides:
put in class MemCache
Parameters:
key - The key with which to find the object.
payload - The object to cache.

addRefCachedKey

protected void addRefCachedKey(String ref,
                               Object key)
Make sure there's an entry in refs for this ref that includes this key.

Parameters:
ref - The entity reference string.
key - The cache entry key dependent on this entity ref.

clear

public void clear()
Description copied from interface: Cache
Clear all entries.

Specified by:
clear in interface Cache
Overrides:
clear in class MemCache

remove

public void remove(Object key)
Description copied from interface: Cache
Remove this entry from the cache.

Specified by:
remove in interface Cache
Overrides:
remove in class MemCache
Parameters:
key - The cache key.

getDescription

public String getDescription()
Description copied from interface: Cacher
Return a description of the cacher.

Specified by:
getDescription in interface Cacher
Overrides:
getDescription in class MemCache
Returns:
The cacher's description.

update

public void update(Observable o,
                   Object arg)
Description copied from class: MemCache
This method is called whenever the observed object is changed. An application calls an Observable object's notifyObservers method to have all the object's observers notified of the change. default implementation is to cause the courier service to deliver to the interface controlled by my controller. Extensions can override.

Specified by:
update in interface Observer
Overrides:
update in class MemCache
Parameters:
o - the observable object.
arg - an argument passed to the notifyObservers method.

continueUpdate

protected void continueUpdate(Event event)
Complete the update, given an event that we know we need to act upon.

Overrides:
continueUpdate in class MemCache
Parameters:
event - The event to process.

isComplete

public boolean isComplete()
Description copied from interface: Cache
Are we complete?

Specified by:
isComplete in interface Cache
Overrides:
isComplete in class MemCache
Returns:
true if we have all the possible entries cached, false if not.

isComplete

public boolean isComplete(String path)
Description copied from interface: Cache
Are we complete for one level of the reference hierarchy?

Specified by:
isComplete in interface Cache
Overrides:
isComplete in class MemCache
Parameters:
path - The reference to the completion level.
Returns:
true if we have all the possible entries cached, false if not.