Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.opensymphony.oscache.general
Class GeneralCacheAdministrator

    java.lang.Object
      com.opensymphony.oscache.base.AbstractCacheAdministrator
          com.opensymphony.oscache.general.GeneralCacheAdministrator

All Implemented Interfaces:
  java.io.Serializable

public class GeneralCacheAdministrator
extends AbstractCacheAdministrator

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: 1.8 $
Author:
  Francois Beauregard, Alain Bergevin
See Also:
  Serialized Form

Field Summary

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, CACHE_MEMORY_KEY, cacheCapacity, config, listenerList, PERSISTENCE_CLASS`

Constructor Summary
`GeneralCacheAdministrator()` Create the cache administrator.
`GeneralCacheAdministrator(java.util.Properties p)` Create the cache administrator with the specified properties

Method Summary
`void` | `cancelUpdate(java.lang.String key)` Cancels a pending cache update.
`void` | `destroy()` Shuts down the cache administrator.
`void` | `flushAll()` Flush the entire cache immediately.
`void` | `flushAll(java.util.Date date)` Flush the entire cache at the given date.
`void` | `flushEntry(java.lang.String key)` Flushes a single cache entry.
`void` | `flushGroup(java.lang.String group)` Flushes all items that belong to the specified group.
`void` | `flushPattern(java.lang.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
`java.lang.Object` | `getFromCache(java.lang.String key)` Get an object from the cache
`java.lang.Object` | `getFromCache(java.lang.String key, int refreshPeriod)` Get an object from the cache
`java.lang.Object` | `getFromCache(java.lang.String key, int refreshPeriod, java.lang.String cronExpression)` Get an object from the cache
`void` | `putInCache(java.lang.String key, java.lang.Object content)` Put an object in a cache
`void` | `putInCache(java.lang.String key, java.lang.Object content, EntryRefreshPolicy policy)` Put an object in a cache
`void` | `putInCache(java.lang.String key, java.lang.Object content, java.lang.String[] groups)` Puts an object in a cache
`void` | `putInCache(java.lang.String key, java.lang.Object content, java.lang.String[] groups, EntryRefreshPolicy policy)` Puts an object in a 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, isUnlimitedDiskCache, setAlgorithmClass, setPersistenceListener`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### GeneralCacheAdministrator

    public GeneralCacheAdministrator()

  Create the cache administrator.

### GeneralCacheAdministrator

    public GeneralCacheAdministrator(java.util.Properties p)

  Create the cache administrator with the specified properties

Method Detail

### getCache

    public Cache getCache()

  Grabs a cache

  Returns:
    The cache

### getFromCache

    public java.lang.Object getFromCache(java.lang.String key)
                                  throws NeedsRefreshException

  Get an object from the cache

  Parameters:
    `key` - The key entered by the user.
  Returns:
    The object from cache
  Throws:
    `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`).

### getFromCache

    public java.lang.Object getFromCache(java.lang.String key,
                                         int refreshPeriod)
                                  throws NeedsRefreshException

  Get an object from the cache

  Parameters:
    `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`
  Returns:
    The object from cache
  Throws:
    `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`).

### getFromCache

    public java.lang.Object getFromCache(java.lang.String key,
                                         int refreshPeriod,
                                         java.lang.String cronExpression)
                                  throws NeedsRefreshException

  Get an object from the cache

  Parameters:
    `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.
  Returns:
    The object from cache
  Throws:
    `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`).

### cancelUpdate

    public void cancelUpdate(java.lang.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.

  Parameters:
    `key` - The cache entry key to cancel the update of.

### destroy

    public void destroy()

  Shuts down the cache administrator.

### flushAll

    public void flushAll()

  Flush the entire cache immediately.

### flushAll

    public void flushAll(java.util.Date date)

  Flush the entire cache at the given date.

  Parameters:
    `date` - The time to flush

### flushEntry

    public void flushEntry(java.lang.String key)

  Flushes a single cache entry.

### flushGroup

    public void flushGroup(java.lang.String group)

  Flushes all items that belong to the specified group.

  Parameters:
    `group` - The name of the group to flush

### flushPattern

    public void flushPattern(java.lang.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.

  Parameters:
    `pattern` - Pattern.

### putInCache

    public void putInCache(java.lang.String key,
                           java.lang.Object content,
                           EntryRefreshPolicy policy)

  Put an object in a cache

  Parameters:
    `key` - The key entered by the user
    `content` - The object to store
    `policy` - Object that implements refresh policy logic

### putInCache

    public void putInCache(java.lang.String key,
                           java.lang.Object content)

  Put an object in a cache

  Parameters:
    `key` - The key entered by the user
    `content` - The object to store

### putInCache

    public void putInCache(java.lang.String key,
                           java.lang.Object content,
                           java.lang.String[] groups)

  Puts an object in a cache

  Parameters:
    `key` - The unique key for this cached object
    `content` - The object to store
    `groups` - The groups that this object belongs to

### putInCache

    public void putInCache(java.lang.String key,
                           java.lang.Object content,
                           java.lang.String[] groups,
                           EntryRefreshPolicy policy)

  Puts an object in a cache

  Parameters:
    `key` - The unique key for this cached object
    `content` - The object to store
    `groups` - The groups that this object belongs to
    `policy` - The refresh policy to use

### setCacheCapacity

    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.

  Overrides:
    `setCacheCapacity` in class `AbstractCacheAdministrator`
  Parameters:
    `capacity` - The new capacity of the cache

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| See www.opensymphony.com for more information.
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD