| java.lang.Object com.opensymphony.oscache.base.AbstractCacheAdministrator com.opensymphony.oscache.web.ServletCacheAdministrator
ServletCacheAdministrator | public class ServletCacheAdministrator extends AbstractCacheAdministrator implements Serializable(Code) | | 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.
author: Mike Cannon-Brookes author: Todd Gochenour author: Francois Beauregard author: Alain Bergevin author: Chris Miller version: $Revision: 463 $ |
Method Summary | |
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. | public static void | destroyInstance(ServletContext context) Shuts down all servlet cache administrators. | protected void | finalizeListeners(Cache cache) | public void | flushAll(Date date) | public void | flushAll() Flush all scopes instantly. | public String | generateEntryKey(String key, HttpServletRequest request, int scope) Generates a cache entry key. | public String | generateEntryKey(String key, HttpServletRequest request, int scope, String language) Generates a cache entry key. | public String | generateEntryKey(String key, HttpServletRequest request, int scope, String language, String suffix) Generates a cache entry key. | public Cache | getAppScopeCache(ServletContext context) A convenience method to retrieve the application scope cache
Parameters: context - the current ServletContext the application scope cache. | public Cache | getCache(HttpServletRequest request, int scope) | public String | getCacheKey() Get the cache key from the properties. | public Date | getFlushTime(int scope) Get the flush time for a particular scope.
Parameters: scope - The scope to get the flush time for. | public Object | getFromCache(int scope, HttpServletRequest request, String key, int refreshPeriod) | public static ServletCacheAdministrator | getInstance(ServletContext context) | public static synchronized ServletCacheAdministrator | getInstance(ServletContext context, Properties p) Obtain an instance of the CacheAdministrator
Parameters: context - The ServletContext that this CacheAdministrator is a Singleton under Parameters: p - the properties to use for the cache if the cache administrator has not beencreated yet. | public static ServletCacheAdministrator | getInstanceFromKey(ServletContext context, String key) | public Cache | getSessionScopeCache(HttpSession session) A convenience method to retrieve the session scope cache
Parameters: session - the current HttpSession the session scope cache for this session. | protected String | getSortedQueryString(HttpServletRequest request) Creates a string that contains all of the request parameters and their
values in a single string. | public boolean | isScopeFlushed(CacheEntry cacheEntry, int scope) Checks if the given scope was flushed more recently than the CacheEntry provided. | 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. | public void | putInCache(int scope, HttpServletRequest request, String key, Object content, EntryRefreshPolicy policy) Put an object in the cache. | 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). | public void | setFlushTime(Date date, int scope) | public void | setFlushTime(int scope) Set the flush time for a specific scope to the current time. |
APPLICATION_SCOPE_NAME | final public static String APPLICATION_SCOPE_NAME(Code) | | |
HASH_KEY_CONTEXT_TMPDIR | final public static String HASH_KEY_CONTEXT_TMPDIR(Code) | | 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.
|
HASH_KEY_SCOPE | final public static String HASH_KEY_SCOPE(Code) | | 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.
|
HASH_KEY_SESSION_ID | final public static String HASH_KEY_SESSION_ID(Code) | | 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.
|
SESSION_SCOPE_NAME | final public static String SESSION_SCOPE_NAME(Code) | | Constants for scope's name
|
addScopeEventListener | public void addScopeEventListener(ScopeEventListener listener)(Code) | | Register a listener for Cache Map events.
Parameters: listener - The object that listens to events. |
cancelUpdate | public void cancelUpdate(int scope, HttpServletRequest request, 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: scope - The cache scope Parameters: request - The servlet request Parameters: key - The cache entry key to cancel the update of. |
destroyInstance | public static void destroyInstance(ServletContext context)(Code) | | Shuts down all servlet cache administrators. This should usually only
be called when the controlling application shuts down.
|
finalizeListeners | protected void finalizeListeners(Cache cache)(Code) | | Finalizes all the listeners that are associated with the given cache object
|
flushAll | public void flushAll(Date date)(Code) | | Flush all scopes at a particular time
Parameters: date - The time to flush the scope |
flushAll | public void flushAll()(Code) | | Flush all scopes instantly.
|
generateEntryKey | public String generateEntryKey(String key, HttpServletRequest request, int scope)(Code) | | 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.
Parameters: key - The key entered by the user Parameters: request - The current request Parameters: scope - The scope this cache entry is under The generated cache key |
generateEntryKey | public String generateEntryKey(String key, HttpServletRequest request, int scope, String language)(Code) | | 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.
Parameters: key - The key entered by the user Parameters: request - The current request Parameters: scope - The scope this cache entry is under Parameters: language - The ISO-639 language code to distinguish different pages in application scope The generated cache key |
generateEntryKey | public String generateEntryKey(String key, HttpServletRequest request, int scope, String language, String suffix)(Code) | | 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.
Parameters: key - The key entered by the user Parameters: request - The current request Parameters: scope - The scope this cache entry is under Parameters: language - The ISO-639 language code to distinguish different pages in application scope Parameters: suffix - The ability to put a suffix at the end of the key The generated cache key |
getAppScopeCache | public Cache getAppScopeCache(ServletContext context)(Code) | | A convenience method to retrieve the application scope cache
Parameters: context - the current ServletContext the application scope cache. If none is present, one willbe created. |
getCache | public Cache getCache(HttpServletRequest request, int scope)(Code) | | Grabs the cache for the specified scope
Parameters: request - The current request Parameters: scope - The scope of this cache (PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE ) The cache |
getCacheKey | public String getCacheKey()(Code) | | Get the cache key from the properties. Set it to a default value if it
is not present in the properties
The cache.key property or the DEFAULT_CACHE_KEY |
getFlushTime | public Date getFlushTime(int scope)(Code) | | Get the flush time for a particular scope.
Parameters: scope - The scope to get the flush time for. A date representing the time this scope was last flushed.Returns null if it has never been flushed. |
getFromCache | public Object getFromCache(int scope, HttpServletRequest request, String key, int refreshPeriod) throws NeedsRefreshException(Code) | | Retrieve an item from the cache
Parameters: scope - The cache scope Parameters: request - The servlet request Parameters: key - The key of the object to retrieve Parameters: refreshPeriod - The time interval specifying if an entry needs refresh The requested object throws: NeedsRefreshException - |
getInstance | public static ServletCacheAdministrator getInstance(ServletContext context)(Code) | | Obtain an instance of the CacheAdministrator
Parameters: context - The ServletContext that this CacheAdministrator is a Singleton under Returns the CacheAdministrator instance for this context |
getInstance | public static synchronized ServletCacheAdministrator getInstance(ServletContext context, Properties p)(Code) | | Obtain an instance of the CacheAdministrator
Parameters: context - The ServletContext that this CacheAdministrator is a Singleton under Parameters: p - the properties to use for the cache if the cache administrator has not beencreated yet. Once the administrator has been created, the properties parameter isignored for all future invocations. If a null value is passed in, then the propertiesare loaded from the oscache.properties file in the classpath. Returns the CacheAdministrator instance for this context |
getInstanceFromKey | public static ServletCacheAdministrator getInstanceFromKey(ServletContext context, String key)(Code) | | Obtain an instance of the CacheAdministrator for the specified key
Parameters: context - The ServletContext that this CacheAdministrator is a Singleton under Parameters: key - the cachekey or admincachekey for the CacheAdministrator wanted Returns the CacheAdministrator instance for this context, or null if noCacheAdministrator exists with the key supplied |
getSessionScopeCache | public Cache getSessionScopeCache(HttpSession session)(Code) | | A convenience method to retrieve the session scope cache
Parameters: session - the current HttpSession the session scope cache for this session. If none is present,one will be created. |
getSortedQueryString | protected String getSortedQueryString(HttpServletRequest request)(Code) | | 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 .
|
isScopeFlushed | public boolean isScopeFlushed(CacheEntry cacheEntry, int scope)(Code) | | Checks if the given scope was flushed more recently than the CacheEntry provided.
Used to determine whether to refresh the particular CacheEntry.
Parameters: cacheEntry - The cache entry which we're seeing whether to refresh Parameters: scope - The scope we're checking Whether or not the scope has been flushed more recently than this cache entry was updated. |
logError | public void logError(String message)(Code) | | Log error messages to commons logging.
Parameters: message - Message to log. |
putInCache | public void putInCache(int scope, HttpServletRequest request, String key, Object content)(Code) | | 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.
Parameters: scope - The cache scope Parameters: request - The servlet request Parameters: key - The object key Parameters: content - The object to add |
putInCache | public void putInCache(int scope, HttpServletRequest request, String key, Object content, EntryRefreshPolicy policy)(Code) | | 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.
Parameters: scope - The cache scope Parameters: request - The servlet request Parameters: key - The object key Parameters: content - The object to add Parameters: policy - The refresh policy |
removeScopeEventListener | public void removeScopeEventListener(ScopeEventListener listener)(Code) | | Unregister a listener for Cache Map events.
Parameters: listener - The object that currently listens to events. |
setCacheCapacity | public void setCacheCapacity(int scope, HttpServletRequest request, 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: scope - The cache scope Parameters: request - The servlet request Parameters: capacity - The new capacity |
setFlushTime | public void setFlushTime(Date date, int scope)(Code) | | Set the flush time for a specific scope to a specific time
Parameters: date - The time to flush the scope Parameters: scope - The scope to be flushed |
setFlushTime | public void setFlushTime(int scope)(Code) | | Set the flush time for a specific scope to the current time.
Parameters: scope - The scope to be flushed |
|
|