| java.lang.Object com.opensymphony.oscache.base.AbstractCacheAdministrator com.opensymphony.oscache.general.GeneralCacheAdministrator
GeneralCacheAdministrator | public class GeneralCacheAdministrator extends AbstractCacheAdministrator (Code) | | A GeneralCacheAdministrator creates, flushes and administers the cache.
EXAMPLES :
// ---------------------------------------------------------------
// Typical use with fail over
// ---------------------------------------------------------------
String myKey = "myKey";
String myValue;
int myRefreshPeriod = 1000;
try {
// Get from the cache
myValue = (String) admin.getFromCache(myKey, myRefreshPeriod);
} catch (NeedsRefreshException nre) {
try {
// Get the value (probably by calling an EJB)
myValue = "This is the content retrieved.";
// Store in the cache
admin.putInCache(myKey, myValue);
} catch (Exception ex) {
// We have the current content if we want fail-over.
myValue = (String) nre.getCacheContent();
// It is essential that cancelUpdate is called if the
// cached content is not rebuilt
admin.cancelUpdate(myKey);
}
}
// ---------------------------------------------------------------
// Typical use without fail over
// ---------------------------------------------------------------
String myKey = "myKey";
String myValue;
int myRefreshPeriod = 1000;
try {
// Get from the cache
myValue = (String) admin.getFromCache(myKey, myRefreshPeriod);
} catch (NeedsRefreshException nre) {
try {
// Get the value (probably by calling an EJB)
myValue = "This is the content retrieved.";
// Store in the cache
admin.putInCache(myKey, myValue);
updated = true;
} finally {
if (!updated) {
// It is essential that cancelUpdate is called if the
// cached content could not be rebuilt
admin.cancelUpdate(myKey);
}
}
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
version: $Revision: 254 $ author: Francois Beauregard author: Alain Bergevin |
Method Summary | |
public void | cancelUpdate(String key) Cancels a pending cache update. | public void | destroy() Shuts down the cache administrator. | public void | flushAll() Flush the entire cache immediately. | public void | flushAll(Date date) Flush the entire cache at the given date. | public void | flushEntry(String key) Flushes a single cache entry. | public void | flushGroup(String group) Flushes all items that belong to the specified group. | public void | flushPattern(String pattern) Allows to flush all items that have a specified pattern in the key. | public Cache | getCache() | public Object | getFromCache(String key) Get an object from the cache
Parameters: key - The key entered by the user. | public Object | getFromCache(String key, int refreshPeriod) Get an object from the cache
Parameters: key - The key entered by the user. Parameters: refreshPeriod - How long the object can stay in cache in seconds. | public Object | getFromCache(String key, int refreshPeriod, String cronExpression) Get an object from the cache
Parameters: key - The key entered by the user. Parameters: refreshPeriod - How long the object can stay in cache in seconds. | public void | putInCache(String key, Object content, EntryRefreshPolicy policy) | public void | putInCache(String key, Object content) | public void | putInCache(String key, Object content, String[] groups) | public void | putInCache(String key, Object content, String[] groups, EntryRefreshPolicy policy) | public void | removeEntry(String key) | public void | setCacheCapacity(int capacity) Sets the cache capacity (number of items). |
GeneralCacheAdministrator | public GeneralCacheAdministrator()(Code) | | Create the cache administrator.
|
GeneralCacheAdministrator | public GeneralCacheAdministrator(Properties p)(Code) | | Create the cache administrator with the specified properties
|
cancelUpdate | public void cancelUpdate(String key)(Code) | | Cancels a pending cache update. This should only be called by a thread
that received a
NeedsRefreshException and was unable to generate
some new cache content.
Parameters: key - The cache entry key to cancel the update of. |
destroy | public void destroy()(Code) | | Shuts down the cache administrator.
|
flushAll | public void flushAll()(Code) | | Flush the entire cache immediately.
|
flushAll | public void flushAll(Date date)(Code) | | Flush the entire cache at the given date.
Parameters: date - The time to flush |
flushEntry | public void flushEntry(String key)(Code) | | Flushes a single cache entry.
|
flushGroup | public void flushGroup(String group)(Code) | | Flushes all items that belong to the specified group.
Parameters: group - The name of the group to flush |
getCache | public Cache getCache()(Code) | | Grabs a cache
The cache |
getFromCache | public Object getFromCache(String key) throws NeedsRefreshException(Code) | | Get an object from the cache
Parameters: key - The key entered by the user. The object from cache throws: NeedsRefreshException - when no cache entry could be found with thesupplied key, or when an entry was found but is considered out of date. Ifthe cache entry is a new entry that is currently being constructed this methodwill block until the new entry becomes available. Similarly, it will block ifa stale entry is currently being rebuilt by another thread and cache blocking isenabled (cache.blocking=true ). |
getFromCache | public Object getFromCache(String key, int refreshPeriod) throws NeedsRefreshException(Code) | | Get an object from the cache
Parameters: key - The key entered by the user. Parameters: refreshPeriod - How long the object can stay in cache in seconds. Toallow the entry to stay in the cache indefinitely, supply a value ofCacheEntry.INDEFINITE_EXPIRY The object from cache throws: NeedsRefreshException - when no cache entry could be found with thesupplied key, or when an entry was found but is considered out of date. Ifthe cache entry is a new entry that is currently being constructed this methodwill block until the new entry becomes available. Similarly, it will block ifa stale entry is currently being rebuilt by another thread and cache blocking isenabled (cache.blocking=true ). |
getFromCache | public Object getFromCache(String key, int refreshPeriod, String cronExpression) throws NeedsRefreshException(Code) | | Get an object from the cache
Parameters: key - The key entered by the user. Parameters: refreshPeriod - How long the object can stay in cache in seconds. Toallow the entry to stay in the cache indefinitely, supply a value ofCacheEntry.INDEFINITE_EXPIRY Parameters: cronExpression - A cron expression that the age of the cache entrywill be compared to. If the entry is older than the most recent match for thecron expression, the entry will be considered stale. The object from cache throws: NeedsRefreshException - when no cache entry could be found with thesupplied key, or when an entry was found but is considered out of date. Ifthe cache entry is a new entry that is currently being constructed this methodwill block until the new entry becomes available. Similarly, it will block ifa stale entry is currently being rebuilt by another thread and cache blocking isenabled (cache.blocking=true ). |
putInCache | public void putInCache(String key, Object content, EntryRefreshPolicy policy)(Code) | | Put an object in a cache
Parameters: key - The key entered by the user Parameters: content - The object to store Parameters: policy - Object that implements refresh policy logic |
putInCache | public void putInCache(String key, Object content)(Code) | | Put an object in a cache
Parameters: key - The key entered by the user Parameters: content - The object to store |
putInCache | public void putInCache(String key, Object content, String[] groups)(Code) | | Puts an object in a cache
Parameters: key - The unique key for this cached object Parameters: content - The object to store Parameters: groups - The groups that this object belongs to |
putInCache | public void putInCache(String key, Object content, String[] groups, EntryRefreshPolicy policy)(Code) | | Puts an object in a cache
Parameters: key - The unique key for this cached object Parameters: content - The object to store Parameters: groups - The groups that this object belongs to Parameters: policy - The refresh policy to use |
removeEntry | public void removeEntry(String key)(Code) | | Remove an object from the cache
Parameters: key - The key entered by the user. |
setCacheCapacity | public void setCacheCapacity(int capacity)(Code) | | Sets the cache capacity (number of items). If the cache contains
more than capacity items then items will be removed
to bring the cache back down to the new size.
Parameters: capacity - The new capacity of the cache |
|
|