Save This Page
Home » oscache-2.4.1-full » com.opensymphony.oscache » general » [javadoc | source]
com.opensymphony.oscache.general
public class: GeneralCacheAdministrator [javadoc | source]
java.lang.Object
   com.opensymphony.oscache.base.AbstractCacheAdministrator
      com.opensymphony.oscache.general.GeneralCacheAdministrator

All Implemented Interfaces:
    Serializable

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);
}
}
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
Fields inherited from com.opensymphony.oscache.base.AbstractCacheAdministrator:
CACHE_MEMORY_KEY,  CACHE_CAPACITY_KEY,  CACHE_ALGORITHM_KEY,  CACHE_DISK_UNLIMITED_KEY,  CACHE_BLOCKING_KEY,  PERSISTENCE_CLASS_KEY,  CACHE_PERSISTENCE_OVERFLOW_KEY,  CACHE_ENTRY_EVENT_LISTENERS_KEY,  config,  listenerList,  algorithmClass,  cacheCapacity
Constructor:
 public GeneralCacheAdministrator() 
 public GeneralCacheAdministrator(Properties p) 
    Create the cache administrator with the specified properties
Method from com.opensymphony.oscache.general.GeneralCacheAdministrator Summary:
cancelUpdate,   destroy,   flushAll,   flushAll,   flushEntry,   flushGroup,   flushPattern,   getCache,   getFromCache,   getFromCache,   getFromCache,   putInCache,   putInCache,   putInCache,   putInCache,   removeEntry,   setCacheCapacity
Methods from com.opensymphony.oscache.base.AbstractCacheAdministrator:
configureStandardListeners,   finalizeListeners,   getCacheEventListeners,   getProperty,   isBlocking,   isMemoryCaching,   isOverflowPersistence,   isUnlimitedDiskCache,   setAlgorithmClass,   setCacheCapacity,   setOverflowPersistence,   setPersistenceListener
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.opensymphony.oscache.general.GeneralCacheAdministrator Detail:
 public  void cancelUpdate(String key) 
    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.
 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) 
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.

    Allows to flush all items that have a specified pattern in the key.
 public Cache getCache() 
    Grabs a cache
 public Object getFromCache(String key) throws NeedsRefreshException 
    Get an object from the cache
 public Object getFromCache(String key,
    int refreshPeriod) throws NeedsRefreshException 
    Get an object from the cache
 public Object getFromCache(String key,
    int refreshPeriod,
    String cronExpression) throws NeedsRefreshException 
    Get an object from the cache
 public  void putInCache(String key,
    Object content) 
    Put an object in a cache
 public  void putInCache(String key,
    Object content,
    EntryRefreshPolicy policy) 
    Put an object in a cache
 public  void putInCache(String key,
    Object content,
    String[] groups) 
    Puts an object in a cache
 public  void putInCache(String key,
    Object content,
    String[] groups,
    EntryRefreshPolicy policy) 
    Puts an object in a cache
 public  void removeEntry(String key) 
    Remove an object from the cache
 public  void setCacheCapacity(int capacity) 
    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.