org.sakaiproject.service.framework.memory
Interface Cache

All Superinterfaces:
Cacher
All Known Subinterfaces:
MultiRefCache, SiteCache
All Known Implementing Classes:
MemCache, MultiRefCacheImpl, SiteCacheImpl

public interface Cache
extends Cacher

A Cache holds objects with keys with a limited lifespan.

When the object expires, the cache may call upon a CacheRefresher to update the key's value. The update is done in a separate thread.

Version:
$Revision: 632 $
Author:
University of Michigan, CHEF Software Development Team

Method Summary
 void clear()
          Clear all entries.
 boolean containsKey(Object key)
          Test for a non expired entry in the cache.
 boolean containsKeyExpiredOrNot(Object key)
          Test for an entry in the cache - expired or not.
 void destroy()
          Clear all entries and shudown the cache.
 void disable()
          Disable the cache.
 boolean disabled()
          Is the cache disabled?
 void enable()
          Enable the cache.
 void expire(Object key)
          Expire this object.
 Object get(Object key)
          Get the non expired entry, or null if not there (or expired)
 List getAll()
          Get all the non-expired non-null entries.
 List getAll(String path)
          Get all the non-expired non-null entries that are in the specified reference path.
 Object getExpiredOrNot(Object key)
          Get the entry, or null if not there (expired entries are returned, too).
 List getIds()
          Get all the keys, modified from resource references to ids by removing the resource prefix.
 List getKeys()
          Get all the keys
 void holdEvents()
          Set the cache to hold events for later processing to assure an atomic "complete" load.
 boolean isComplete()
          Are we complete?
 boolean isComplete(String path)
          Are we complete for one level of the reference hierarchy?
 void processEvents()
          Restore normal event processing in the cache, and process any held events now.
 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 remove(Object key)
          Remove this entry from the cache.
 void setComplete()
          Set the cache to be complete, containing all possible entries.
 void setComplete(String path)
          Set the cache to be complete for one level of the reference hierarchy.
 
Methods inherited from interface org.sakaiproject.service.framework.memory.Cacher
getDescription, getSize, resetCache
 

Method Detail

put

public void put(Object key,
                Object payload,
                int duration)
Cache an object

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)
Cache an object - don't automatically exipire it.

Parameters:
key - The key with which to find the object.
payload - The object to cache.

containsKeyExpiredOrNot

public boolean containsKeyExpiredOrNot(Object key)
Test for an entry in the cache - expired or not.

Parameters:
key - The cache key.
Returns:
true if the key maps to a cache entry, false if not.

containsKey

public boolean containsKey(Object key)
Test for a non expired entry in the cache.

Parameters:
key - The cache key.
Returns:
true if the key maps to a non-expired cache entry, false if not.

expire

public void expire(Object key)
Expire this object.

Parameters:
key - The cache key.

getExpiredOrNot

public Object getExpiredOrNot(Object key)
Get the entry, or null if not there (expired entries are returned, too).

Parameters:
key - The cache key.
Returns:
The payload, or null if the payload is null, the key is not found. (Note: use containsKey() to remove this ambiguity).

get

public Object get(Object key)
Get the non expired entry, or null if not there (or expired)

Parameters:
key - The cache key.
Returns:
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()
Get all the non-expired non-null entries.

Returns:
all the non-expired non-null entries, or an empty list if none.

getAll

public List getAll(String path)
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.
Returns:
all the non-expired non-null entries, or an empty list if none.

getKeys

public List getKeys()
Get all the keys

Returns:
The List of key values (Object).

getIds

public List getIds()
Get all the keys, modified from resource references to ids by removing the resource prefix. Note: only works with String keys.

Returns:
The List of keys converted from references to ids (String).

clear

public void clear()
Clear all entries.


remove

public void remove(Object key)
Remove this entry from the cache.

Parameters:
key - The cache key.

disable

public void disable()
Disable the cache.


enable

public void enable()
Enable the cache.


disabled

public boolean disabled()
Is the cache disabled?

Returns:
true if the cache is disabled, false if it is enabled.

isComplete

public boolean isComplete()
Are we complete?

Returns:
true if we have all the possible entries cached, false if not.

setComplete

public void setComplete()
Set the cache to be complete, containing all possible entries.


isComplete

public boolean isComplete(String path)
Are we complete for one level of the reference hierarchy?

Parameters:
path - The reference to the completion level.
Returns:
true if we have all the possible entries cached, false if not.

setComplete

public void setComplete(String path)
Set the cache to be complete for one level of the reference hierarchy.

Parameters:
path - The reference to the completion level.

holdEvents

public void holdEvents()
Set the cache to hold events for later processing to assure an atomic "complete" load.


processEvents

public void processEvents()
Restore normal event processing in the cache, and process any held events now.


destroy

public void destroy()
Clear all entries and shudown the cache. Don't use after this call.