|
|||||||||||
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.web.ServletCacheAdministrator
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 | |
static String |
APPLICATION_SCOPE_NAME
|
static String |
HASH_KEY_CONTEXT_TMPDIR
Key used to store the servlet container temporary directory in the configuration. |
static String |
HASH_KEY_SCOPE
Key used to store the current scope in the configuration. |
static String |
HASH_KEY_SESSION_ID
Key used to store the current session ID in the configuration. |
static String |
SESSION_SCOPE_NAME
Constants for scope's name |
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 |
Method Summary | |
void |
addScopeEventListener(ScopeEventListener listener)
Register a listener for Cache Map events. |
void |
cancelUpdate(int scope,
javax.servlet.http.HttpServletRequest request,
String key)
Cancels a pending cache update. |
static void |
destroyInstance(javax.servlet.ServletContext context)
Shuts down the cache administrator. |
protected void |
finalizeListeners(Cache cache)
Finalizes all the listeners that are associated with the given cache object |
void |
flushAll()
Flush all scopes instantly. |
void |
flushAll(Date date)
Flush all scopes at a particular time |
String |
generateEntryKey(String key,
javax.servlet.http.HttpServletRequest request,
int scope)
Generates a cache entry key. |
String |
generateEntryKey(String key,
javax.servlet.http.HttpServletRequest request,
int scope,
String language)
Generates a cache entry key. |
String |
generateEntryKey(String key,
javax.servlet.http.HttpServletRequest request,
int scope,
String language,
String suffix)
Generates a cache entry key. |
Cache |
getAppScopeCache(javax.servlet.ServletContext context)
A convenience method to retrieve the application scope cache |
Cache |
getCache(javax.servlet.http.HttpServletRequest request,
int scope)
Grabs the cache for the specified scope |
String |
getCacheKey()
Get the cache key from the properties. |
Date |
getFlushTime(int scope)
Get the flush time for a particular scope. |
Object |
getFromCache(int scope,
javax.servlet.http.HttpServletRequest request,
String key,
int refreshPeriod)
Retrieve an item from the cache |
static ServletCacheAdministrator |
getInstance(javax.servlet.ServletContext context)
Obtain an instance of the CacheAdministrator |
static ServletCacheAdministrator |
getInstance(javax.servlet.ServletContext context,
Properties p)
Obtain an instance of the CacheAdministrator |
Cache |
getSessionScopeCache(javax.servlet.http.HttpSession session)
A convenience method to retrieve the session scope cache |
protected String |
getSortedQueryString(javax.servlet.http.HttpServletRequest request)
Creates a string that contains all of the request parameters and their values in a single string. |
boolean |
isScopeFlushed(CacheEntry cacheEntry,
int scope)
Checks if the given scope was flushed more recently than the CacheEntry provided. |
void |
logError(String message)
Log error messages to commons logging. |
void |
putInCache(int scope,
javax.servlet.http.HttpServletRequest request,
String key,
Object content)
Put an object in the cache |
void |
putInCache(int scope,
javax.servlet.http.HttpServletRequest request,
String key,
Object content,
EntryRefreshPolicy policy)
Put an object in the cache |
void |
removeScopeEventListener(ScopeEventListener listener)
Unregister a listener for Cache Map events. |
void |
setCacheCapacity(int scope,
javax.servlet.http.HttpServletRequest request,
int capacity)
Sets the cache capacity (number of items). |
void |
setFlushTime(Date date,
int scope)
Set the flush time for a specific scope to a specific time |
void |
setFlushTime(int scope)
Set the flush time for a specific scope to the current time. |
Methods inherited from class com.opensymphony.oscache.base.AbstractCacheAdministrator |
configureStandardListeners, getCacheEventListeners, getProperty, isBlocking, isMemoryCaching, isOverflowPersistence, isUnlimitedDiskCache, setAlgorithmClass, setCacheCapacity, setOverflowPersistence, setPersistenceListener |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String SESSION_SCOPE_NAME
public static final String APPLICATION_SCOPE_NAME
public static final String HASH_KEY_SCOPE
public static final String HASH_KEY_SESSION_ID
public static final String HASH_KEY_CONTEXT_TMPDIR
Method Detail |
public static ServletCacheAdministrator getInstance(javax.servlet.ServletContext context)
context
- The ServletContext that this CacheAdministrator is a Singleton under
public static ServletCacheAdministrator getInstance(javax.servlet.ServletContext context, Properties p)
context
- The ServletContext that this CacheAdministrator is a Singleton underp
- the properties to use for the cache if the cache administrator has not been
created yet. Once the administrator has been created, the properties parameter is
ignored for all future invocations. If a null value is passed in, then the properties
are loaded from the oscache.properties file in the classpath.
public static void destroyInstance(javax.servlet.ServletContext context)
public Cache getCache(javax.servlet.http.HttpServletRequest request, int scope)
request
- The current requestscope
- The scope of this cache (PageContext.APPLICATION_SCOPE
or PageContext.SESSION_SCOPE
)
public Cache getAppScopeCache(javax.servlet.ServletContext context)
context
- the current ServletContext
public Cache getSessionScopeCache(javax.servlet.http.HttpSession session)
session
- the current HttpSession
public String getCacheKey()
public void setFlushTime(Date date, int scope)
date
- The time to flush the scopescope
- The scope to be flushedpublic void setFlushTime(int scope)
scope
- The scope to be flushedpublic Date getFlushTime(int scope)
scope
- The scope to get the flush time for.
public Object getFromCache(int scope, javax.servlet.http.HttpServletRequest request, String key, int refreshPeriod) throws NeedsRefreshException
scope
- The cache scoperequest
- The servlet requestkey
- The key of the object to retrieverefreshPeriod
- The time interval specifying if an entry needs refresh
NeedsRefreshException
public boolean isScopeFlushed(CacheEntry cacheEntry, int scope)
cacheEntry
- The cache entry which we're seeing whether to refreshscope
- The scope we're checking
public void addScopeEventListener(ScopeEventListener listener)
listener
- The object that listens to events.public void cancelUpdate(int scope, javax.servlet.http.HttpServletRequest request, String key)
NeedsRefreshException
and was unable to generate
some new cache content.
scope
- The cache scoperequest
- The servlet requestkey
- The cache entry key to cancel the update of.public void flushAll(Date date)
date
- The time to flush the scopepublic void flushAll()
public String generateEntryKey(String key, javax.servlet.http.HttpServletRequest request, int scope)
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.
key
- The key entered by the userrequest
- The current requestscope
- The scope this cache entry is under
public String generateEntryKey(String key, javax.servlet.http.HttpServletRequest request, int scope, String language)
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.
key
- The key entered by the userrequest
- The current requestscope
- The scope this cache entry is underlanguage
- The ISO-639 language code to distinguish different pages in application scope
public String generateEntryKey(String key, javax.servlet.http.HttpServletRequest request, int scope, String language, String suffix)
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.
key
- The key entered by the userrequest
- The current requestscope
- The scope this cache entry is underlanguage
- The ISO-639 language code to distinguish different pages in application scopesuffix
- The ability to put a suffix at the end of the key
protected String getSortedQueryString(javax.servlet.http.HttpServletRequest request)
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 void logError(String message)
message
- Message to log.public void putInCache(int scope, javax.servlet.http.HttpServletRequest request, String key, Object content)
scope
- The cache scoperequest
- The servlet requestkey
- The object keycontent
- The object to addpublic void putInCache(int scope, javax.servlet.http.HttpServletRequest request, String key, Object content, EntryRefreshPolicy policy)
scope
- The cache scoperequest
- The servlet requestkey
- The object keycontent
- The object to addpolicy
- The refresh policypublic void setCacheCapacity(int scope, javax.servlet.http.HttpServletRequest request, int capacity)
capacity
items then items will be removed
to bring the cache back down to the new size.
scope
- The cache scoperequest
- The servlet requestcapacity
- The new capacitypublic void removeScopeEventListener(ScopeEventListener listener)
listener
- The object that currently listens to events.protected void finalizeListeners(Cache cache)
finalizeListeners
in class AbstractCacheAdministrator
|
OSCache Project Page | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |