| java.lang.Object org.sakaiproject.memory.impl.MemCache
All known Subclasses: org.sakaiproject.memory.impl.MultiRefCacheImpl, org.sakaiproject.memory.impl.HardCache,
MemCache | public class MemCache implements Cache,Runnable,Observer(Code) | |
A Cache of objects with keys with a limited lifespan.
When the object expires, the cache calls upon a CacheRefresher to update the key's value. The update is done in a separate thread.
|
Constructor Summary | |
public | MemCache(BasicMemoryService memoryService, EventTrackingService eventTrackingService) Construct the Cache. | public | MemCache(BasicMemoryService memoryService, EventTrackingService eventTrackingService, CacheRefresher refresher, String pattern) Construct the Cache. | public | MemCache(BasicMemoryService memoryService, EventTrackingService eventTrackingService, CacheRefresher refresher, long sleep) Construct the Cache. | public | MemCache(BasicMemoryService memoryService, EventTrackingService eventTrackingService, long sleep, String pattern) Construct the Cache. |
Method Summary | |
public void | attachDerivedCache(DerivedCache cache) | public void | clear() Clear all entries. | public boolean | containsKey(Object key) Test for a non expired entry in the cache.
Parameters: key - The cache key. | public boolean | containsKeyExpiredOrNot(Object key) Test for an entry in the cache - expired or not.
Parameters: key - The cache key. | protected void | continueUpdate(Event event) Complete the update, given an event that we know we need to act upon. | public void | destroy() Clean up. | public void | disable() Disable the cache. | public boolean | disabled() | public void | enable() Enable the cache. | public void | expire(Object key) Expire this object. | public Object | get(Object key) Get the non expired entry, or null if not there (or expired)
Parameters: key - The cache key. | public List | getAll() Get all the non-expired non-null entries. | public List | getAll(String path) Get all the non-expired non-null entries that are in the specified reference path. | public String | getDescription() Return a description of the cacher. | public Object | getExpiredOrNot(Object key) Get the entry, or null if not there (expired entries are returned, too).
Parameters: key - The cache key. | public List | getIds() Get all the keys, eache modified to remove the resourcePattern prefix. | public List | getKeys() | public long | getSize() Return the size of the cacher - indicating how much memory in use. | public void | holdEvents() Set the cache to hold events for later processing to assure an atomic "complete" load. | public boolean | isComplete() | public boolean | isComplete(String path) Are we complete for one level of the reference hierarchy?
Parameters: path - The reference to the completion level. | public void | processEvents() Restore normal event processing in the cache, and process any held events now. | public void | put(Object key, Object payload, int duration) | public void | put(Object key, Object payload) Cache an object - don't automatically exipire it. | protected String | referencePath(String ref) Compute the reference path (i.e. | public void | remove(Object key) Remove this entry from the cache. | public void | resetCache() Clear out as much as possible anything cached; re-sync any cache that is needed to be kept. | public void | run() Run the expiration thread. | public void | setComplete() Set the cache to be complete, containing all possible entries. | public void | setComplete(String path) Set the cache to be complete for one level of the reference hierarchy. | protected void | start() Start the expiration thread. | protected void | stop() Stop the expiration thread. | public void | update(Observable o, Object arg) This method is called whenever the observed object is changed. |
m_complete | protected boolean m_complete(Code) | | If true, we have all the entries that there are in the cache.
|
m_disabled | protected boolean m_disabled(Code) | | If true, we are disabled.
|
m_getCount | protected long m_getCount(Code) | | Count of access requests.
|
m_heldEvents | protected List m_heldEvents(Code) | | The events we are holding for later processing.
|
m_hitCount | protected long m_hitCount(Code) | | Count of access requests satisfied with a cached entry.
|
m_holdEventProcessing | protected boolean m_holdEventProcessing(Code) | | If true, we are going to hold any events we see in the m_heldEvents list for later processing.
|
m_map | protected Map m_map(Code) | | Map holding cached entries.
|
m_partiallyComplete | protected Set m_partiallyComplete(Code) | | Alternate isComplete, based on patterns.
|
m_putCount | protected long m_putCount(Code) | | Count of things put into the cache.
|
m_refresher | protected CacheRefresher m_refresher(Code) | | The object that will deal with expired entries.
|
m_refresherSleep | protected long m_refresherSleep(Code) | | The number of seconds to sleep between expiration checks.
|
m_resourcePattern | protected String m_resourcePattern(Code) | | The string that all resources in this cache will start with.
|
m_softRefs | protected boolean m_softRefs(Code) | | If true, we do soft references, else we do hard ones.
|
m_thread | protected Thread m_thread(Code) | | The thread which runs the expiration check.
|
m_threadStop | protected boolean m_threadStop(Code) | | My thread's quit flag.
|
MemCache | public MemCache(BasicMemoryService memoryService, EventTrackingService eventTrackingService, CacheRefresher refresher, String pattern)(Code) | | Construct the Cache. Attempts to keep complete on Event notification by calling the refresher.
Parameters: refresher - The object that will handle refreshing of event notified modified or added entries. Parameters: pattern - The "startsWith()" string for all resources that may be in this cache - if null, don't watch events for updates. |
MemCache | public MemCache(BasicMemoryService memoryService, EventTrackingService eventTrackingService, CacheRefresher refresher, long sleep)(Code) | | Construct the Cache. Automatic refresh handling if refresher is not null.
Parameters: refresher - The object that will handle refreshing of expired entries. Parameters: sleep - The number of seconds to sleep between expiration checks. |
MemCache | public MemCache(BasicMemoryService memoryService, EventTrackingService eventTrackingService, long sleep, String pattern)(Code) | | Construct the Cache. Event scanning if pattern not null - will expire entries.
Parameters: sleep - The number of seconds to sleep between expiration checks. Parameters: pattern - The "startsWith()" string for all resources that may be in this cache - if null, don't watch events for expiration. |
clear | public void clear()(Code) | | Clear all entries.
|
containsKey | public boolean containsKey(Object key)(Code) | | Test for a non expired entry in the cache.
Parameters: key - The cache key. true if the key maps to a non-expired cache entry, false if not. |
containsKeyExpiredOrNot | public boolean containsKeyExpiredOrNot(Object key)(Code) | | Test for an entry in the cache - expired or not.
Parameters: key - The cache key. true if the key maps to a cache entry, false if not. |
continueUpdate | protected void continueUpdate(Event event)(Code) | | Complete the update, given an event that we know we need to act upon.
Parameters: event - The event to process. |
destroy | public void destroy()(Code) | | Clean up.
|
disable | public void disable()(Code) | | Disable the cache.
|
disabled | public boolean disabled()(Code) | | Is the cache disabled?
true if the cache is disabled, false if it is enabled. |
enable | public void enable()(Code) | | Enable the cache.
|
expire | public void expire(Object key)(Code) | | Expire this object.
Parameters: key - The cache key. |
get | public Object get(Object key)(Code) | | Get the non expired entry, or null if not there (or expired)
Parameters: key - The cache key. The payload, or null if the payload is null, the key is not found, or the entry has expired (Note: use containsKey() to remove this ambiguity). |
getAll | public List getAll()(Code) | | Get all the non-expired non-null entries.
all the non-expired non-null entries, or an empty list if none. |
getAll | public List getAll(String path)(Code) | | Get all the non-expired non-null entries that are in the specified reference path. Note: only works with String keys.
Parameters: path - The reference path. all the non-expired non-null entries, or an empty list if none. |
getDescription | public String getDescription()(Code) | | Return a description of the cacher.
The cacher's description. |
getExpiredOrNot | public Object getExpiredOrNot(Object key)(Code) | | Get the entry, or null if not there (expired entries are returned, too).
Parameters: key - The cache key. The payload, or null if the payload is null, the key is not found. (Note: use containsKey() to remove this ambiguity). |
getIds | public List getIds()(Code) | | Get all the keys, eache modified to remove the resourcePattern prefix. Note: only works with String keys.
The List of keys converted from references to ids (String). |
getKeys | public List getKeys()(Code) | | Get all the keys
The List of key values (Object). |
getSize | public long getSize()(Code) | | Return the size of the cacher - indicating how much memory in use.
The size of the cacher. |
holdEvents | public void holdEvents()(Code) | | Set the cache to hold events for later processing to assure an atomic "complete" load.
|
isComplete | public boolean isComplete()(Code) | | Are we complete?
true if we have all the possible entries cached, false if not. |
isComplete | public boolean isComplete(String path)(Code) | | Are we complete for one level of the reference hierarchy?
Parameters: path - The reference to the completion level. true if we have all the possible entries cached, false if not. |
processEvents | public void processEvents()(Code) | | Restore normal event processing in the cache, and process any held events now.
|
put | public void put(Object key, Object payload, int duration)(Code) | | Cache an object
Parameters: key - The key with which to find the object. Parameters: payload - The object to cache. Parameters: duration - The time to cache the object (seconds). |
put | public void put(Object key, Object payload)(Code) | | Cache an object - don't automatically exipire it.
Parameters: key - The key with which to find the object. Parameters: payload - The object to cache. Parameters: duration - The time to cache the object (seconds). |
referencePath | protected String referencePath(String ref)(Code) | | Compute the reference path (i.e. the container) for a given reference.
Parameters: ref - The reference string. The reference root for the given reference. |
remove | public void remove(Object key)(Code) | | Remove this entry from the cache.
Parameters: key - The cache key. |
resetCache | public void resetCache()(Code) | | Clear out as much as possible anything cached; re-sync any cache that is needed to be kept.
|
run | public void run()(Code) | | Run the expiration thread.
|
setComplete | public void setComplete()(Code) | | Set the cache to be complete, containing all possible entries.
|
setComplete | public void setComplete(String path)(Code) | | Set the cache to be complete for one level of the reference hierarchy.
Parameters: path - The reference to the completion level. |
start | protected void start()(Code) | | Start the expiration thread.
|
stop | protected void stop()(Code) | | Stop the expiration thread.
|
update | public void update(Observable o, Object arg)(Code) | | 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.
Parameters: o - the observable object. Parameters: arg - an argument passed to the notifyObservers method. |
|
|