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

All Implemented Interfaces:
    Serializable

A ServletCacheAdministrator creates, flushes and administers the cache.

This is a "servlet Singleton". This means it's not a Singleton in the traditional sense, that is stored in a static instance. It's a Singleton _per web app context_.

Once created it manages the cache path on disk through the oscache.properties file, and also keeps track of the flush times.

Field Summary
public static final  String SESSION_SCOPE_NAME    Constants for scope's name 
public static final  String APPLICATION_SCOPE_NAME     
public static final  String HASH_KEY_SCOPE    Key used to store the current scope in the configuration. This is a hack to let the scope information get passed through to the DiskPersistenceListener, and will be removed in a future release. 
public static final  String HASH_KEY_SESSION_ID    Key used to store the current session ID in the configuration. This is a hack to let the scope information get passed through to the DiskPersistenceListener, and will be removed in a future release. 
public static final  String HASH_KEY_CONTEXT_TMPDIR    Key used to store the servlet container temporary directory in the configuration. This is a hack to let the scope information get passed through to the DiskPersistenceListener, and will be removed in a future release. 
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
Method from com.opensymphony.oscache.web.ServletCacheAdministrator Summary:
addScopeEventListener,   cancelUpdate,   destroyInstance,   finalizeListeners,   flushAll,   flushAll,   generateEntryKey,   generateEntryKey,   generateEntryKey,   getAppScopeCache,   getCache,   getCacheKey,   getFlushTime,   getFromCache,   getInstance,   getInstance,   getInstanceFromKey,   getSessionScopeCache,   getSortedQueryString,   isScopeFlushed,   logError,   putInCache,   putInCache,   removeScopeEventListener,   setCacheCapacity,   setFlushTime,   setFlushTime
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.web.ServletCacheAdministrator Detail:
 public  void addScopeEventListener(ScopeEventListener listener) 
    Register a listener for Cache Map events.
 public  void cancelUpdate(int scope,
    HttpServletRequest request,
    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 static  void destroyInstance(ServletContext context) 
    Shuts down all servlet cache administrators. This should usually only be called when the controlling application shuts down.
 protected  void finalizeListeners(Cache cache) 
    Finalizes all the listeners that are associated with the given cache object
 public  void flushAll() 
    Flush all scopes instantly.
 public  void flushAll(Date date) 
    Flush all scopes at a particular time
 public String generateEntryKey(String key,
    HttpServletRequest request,
    int scope) 
    Generates a cache entry key. If the string key is not specified, the HTTP request URI and QueryString is used. Operating systems that have a filename limitation less than 255 or have filenames that are case insensitive may have issues with key generation where two distinct pages map to the same key.

    POST Requests (which have no distinguishing query string) may also generate identical keys for what is actually different pages. In these cases, specify an explicit key attribute for the CacheTag.

 public String generateEntryKey(String key,
    HttpServletRequest request,
    int scope,
    String language) 
    Generates a cache entry key. If the string key is not specified, the HTTP request URI and QueryString is used. Operating systems that have a filename limitation less than 255 or have filenames that are case insensitive may have issues with key generation where two distinct pages map to the same key.

    POST Requests (which have no distinguishing query string) may also generate identical keys for what is actually different pages. In these cases, specify an explicit key attribute for the CacheTag.

 public String generateEntryKey(String key,
    HttpServletRequest request,
    int scope,
    String language,
    String suffix) 
    Generates a cache entry key.

    If the string key is not specified, the HTTP request URI and QueryString is used. Operating systems that have a filename limitation less than 255 or have filenames that are case insensitive may have issues with key generation where two distinct pages map to the same key.

    POST Requests (which have no distinguishing query string) may also generate identical keys for what is actually different pages. In these cases, specify an explicit key attribute for the CacheTag.

 public Cache getAppScopeCache(ServletContext context) 
    A convenience method to retrieve the application scope cache
 public Cache getCache(HttpServletRequest request,
    int scope) 
    Grabs the cache for the specified scope
 public String getCacheKey() 
    Get the cache key from the properties. Set it to a default value if it is not present in the properties
 public Date getFlushTime(int scope) 
    Get the flush time for a particular scope.
 public Object getFromCache(int scope,
    HttpServletRequest request,
    String key,
    int refreshPeriod) throws NeedsRefreshException 
    Retrieve an item from the cache
 public static ServletCacheAdministrator getInstance(ServletContext context) 
    Obtain an instance of the CacheAdministrator
 public static synchronized ServletCacheAdministrator getInstance(ServletContext context,
    Properties p) 
    Obtain an instance of the CacheAdministrator
 public static ServletCacheAdministrator getInstanceFromKey(ServletContext context,
    String key) 
    Obtain an instance of the CacheAdministrator for the specified key
 public Cache getSessionScopeCache(HttpSession session) 
    A convenience method to retrieve the session scope cache
 protected String getSortedQueryString(HttpServletRequest request) 
    Creates a string that contains all of the request parameters and their values in a single string. This is very similar to HttpServletRequest.getQueryString() except the parameters are sorted by name, and if there is a jsessionid parameter it is filtered out.

    If the request has no parameters, this method returns null.

 public boolean isScopeFlushed(CacheEntry cacheEntry,
    int scope) 
    Checks if the given scope was flushed more recently than the CacheEntry provided. Used to determine whether to refresh the particular CacheEntry.
 public  void logError(String message) 
    Log error messages to commons logging.
 public  void putInCache(int scope,
    HttpServletRequest request,
    String key,
    Object content) 
    Put an object in the cache. This should only be called by a thread that received a NeedsRefreshException . Using session scope the thread has to insure that the session wasn't invalidated in the meantime. CacheTag and CacheFilter guarantee that the same cache is used in cancelUpdate and getFromCache.
 public  void putInCache(int scope,
    HttpServletRequest request,
    String key,
    Object content,
    EntryRefreshPolicy policy) 
    Put an object in the cache. This should only be called by a thread that received a NeedsRefreshException . Using session scope the thread has to insure that the session wasn't invalidated in the meantime. CacheTag and CacheFilter guarantee that the same cache is used in cancelUpdate and getFromCache.
 public  void removeScopeEventListener(ScopeEventListener listener) 
    Unregister a listener for Cache Map events.
 public  void setCacheCapacity(int scope,
    HttpServletRequest request,
    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.
 public  void setFlushTime(int scope) 
    Set the flush time for a specific scope to the current time.
 public  void setFlushTime(Date date,
    int scope) 
    Set the flush time for a specific scope to a specific time