|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.opensymphony.oscache.base.AbstractCacheAdministrator
com.opensymphony.oscache.general.GeneralCacheAdministrator
public class GeneralCacheAdministrator
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);
}
}
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
Field Summary | |
---|---|
private Cache |
applicationCache
Application cache |
private static org.apache.commons.logging.Log |
log
|
Fields inherited from class com.opensymphony.oscache.base.AbstractCacheAdministrator |
---|
algorithmClass, CACHE_ALGORITHM_KEY, CACHE_BLOCKING_KEY, CACHE_CAPACITY_KEY, CACHE_DISK_UNLIMITED_KEY, CACHE_ENTRY_EVENT_LISTENERS_KEY, CACHE_MEMORY_KEY, CACHE_PERSISTENCE_OVERFLOW_KEY, cacheCapacity, config, listenerList, PERSISTENCE_CLASS_KEY |
Constructor Summary | |
---|---|
GeneralCacheAdministrator()
Create the cache administrator. |
|
GeneralCacheAdministrator(Properties p)
Create the cache administrator with the specified properties |
Method Summary | |
---|---|
void |
cancelUpdate(String key)
Cancels a pending cache update. |
private void |
createCache()
Creates a cache in this admin |
void |
destroy()
Shuts down the cache administrator. |
void |
flushAll()
Flush the entire cache immediately. |
void |
flushAll(Date date)
Flush the entire cache at the given date. |
void |
flushEntry(String key)
Flushes a single cache entry. |
void |
flushGroup(String group)
Flushes all items that belong to the specified group. |
void |
flushPattern(String pattern)
Deprecated. For performance and flexibility reasons it is preferable to store cache entries in groups and use the flushGroup(String) method
instead of relying on pattern flushing. |
Cache |
getCache()
Grabs a cache |
Object |
getFromCache(String key)
Get an object from the cache |
Object |
getFromCache(String key,
int refreshPeriod)
Get an object from the cache |
Object |
getFromCache(String key,
int refreshPeriod,
String cronExpression)
Get an object from the cache |
void |
putInCache(String key,
Object content)
Put an object in a cache |
void |
putInCache(String key,
Object content,
EntryRefreshPolicy policy)
Put an object in a cache |
void |
putInCache(String key,
Object content,
String[] groups)
Puts an object in a cache |
void |
putInCache(String key,
Object content,
String[] groups,
EntryRefreshPolicy policy)
Puts an object in a cache |
void |
removeEntry(String key)
Remove an object from the cache |
void |
setCacheCapacity(int capacity)
Sets the cache capacity (number of items). |
Methods inherited from class com.opensymphony.oscache.base.AbstractCacheAdministrator |
---|
configureStandardListeners, finalizeListeners, getCacheEventListeners, getProperty, isBlocking, isMemoryCaching, isOverflowPersistence, isUnlimitedDiskCache, setAlgorithmClass, setOverflowPersistence, setPersistenceListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final transient org.apache.commons.logging.Log log
private Cache applicationCache
Constructor Detail |
---|
public GeneralCacheAdministrator()
public GeneralCacheAdministrator(Properties p)
Method Detail |
---|
public Cache getCache()
public void removeEntry(String key)
key
- The key entered by the user.public Object getFromCache(String key) throws NeedsRefreshException
key
- The key entered by the user.
NeedsRefreshException
- when no cache entry could be found with the
supplied key, or when an entry was found but is considered out of date. If
the cache entry is a new entry that is currently being constructed this method
will block until the new entry becomes available. Similarly, it will block if
a stale entry is currently being rebuilt by another thread and cache blocking is
enabled (cache.blocking=true
).public Object getFromCache(String key, int refreshPeriod) throws NeedsRefreshException
key
- The key entered by the user.refreshPeriod
- How long the object can stay in cache in seconds. To
allow the entry to stay in the cache indefinitely, supply a value of
CacheEntry.INDEFINITE_EXPIRY
NeedsRefreshException
- when no cache entry could be found with the
supplied key, or when an entry was found but is considered out of date. If
the cache entry is a new entry that is currently being constructed this method
will block until the new entry becomes available. Similarly, it will block if
a stale entry is currently being rebuilt by another thread and cache blocking is
enabled (cache.blocking=true
).public Object getFromCache(String key, int refreshPeriod, String cronExpression) throws NeedsRefreshException
key
- The key entered by the user.refreshPeriod
- How long the object can stay in cache in seconds. To
allow the entry to stay in the cache indefinitely, supply a value of
CacheEntry.INDEFINITE_EXPIRY
cronExpression
- A cron expression that the age of the cache entry
will be compared to. If the entry is older than the most recent match for the
cron expression, the entry will be considered stale.
NeedsRefreshException
- when no cache entry could be found with the
supplied key, or when an entry was found but is considered out of date. If
the cache entry is a new entry that is currently being constructed this method
will block until the new entry becomes available. Similarly, it will block if
a stale entry is currently being rebuilt by another thread and cache blocking is
enabled (cache.blocking=true
).public void cancelUpdate(String key)
NeedsRefreshException
and was unable to generate
some new cache content.
key
- The cache entry key to cancel the update of.public void destroy()
public void flushAll()
public void flushAll(Date date)
date
- The time to flushpublic void flushEntry(String key)
public void flushGroup(String group)
group
- The name of the group to flushpublic void flushPattern(String pattern)
flushGroup(String)
method
instead of relying on pattern flushing.
pattern
- Pattern.public void putInCache(String key, Object content, EntryRefreshPolicy policy)
key
- The key entered by the usercontent
- The object to storepolicy
- Object that implements refresh policy logicpublic void putInCache(String key, Object content)
key
- The key entered by the usercontent
- The object to storepublic void putInCache(String key, Object content, String[] groups)
key
- The unique key for this cached objectcontent
- The object to storegroups
- The groups that this object belongs topublic void putInCache(String key, Object content, String[] groups, EntryRefreshPolicy policy)
key
- The unique key for this cached objectcontent
- The object to storegroups
- The groups that this object belongs topolicy
- The refresh policy to usepublic void setCacheCapacity(int capacity)
capacity
items then items will be removed
to bring the cache back down to the new size.
setCacheCapacity
in class AbstractCacheAdministrator
capacity
- The new capacity of the cacheprivate void createCache()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |