|
||||||||||
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
public class 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
|
private static short |
AVERAGE_KEY_LENGTH
Constant for Key generation. |
private static String |
CACHE_ADMINISTRATOR_KEY_SUFFIX
The suffix added to the cache key used to store a ServletCacheAdministrator will be stored in the ServletContext |
private static String |
CACHE_ADMINISTRATORS_KEY
The key under which an array of all ServletCacheAdministrator objects will be stored in the ServletContext |
private static String |
CACHE_KEY_KEY
|
private static String |
CACHE_USE_HOST_DOMAIN_KEY
Constants for properties read/written from/to file |
private String |
cacheKey
Key to use for storing and retrieving Object in contexts (Servlet, session). |
private javax.servlet.ServletContext |
context
Required so we can look up the app scope cache without forcing a session creation. |
private static String |
DEFAULT_CACHE_KEY
The default cache key that is used to store the cache in context. |
private static String |
FILE_SEPARATOR
The string to use as a file separator. |
private static char |
FILE_SEPARATOR_CHAR
The character to use as a file separator. |
private Map |
flushTimes
Map containing the flush times of different scopes |
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. |
private static org.apache.commons.logging.Log |
log
|
private static String |
m_strBase64Chars
Usable caracters for key generation |
static String |
SESSION_SCOPE_NAME
Constants for scope's name |
private boolean |
useHostDomainInKey
Set property cache.use.host.domain.in.key=true to add domain information to key generation for hosting multiple sites. |
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 |
Constructor Summary | |
---|---|
private |
ServletCacheAdministrator(javax.servlet.ServletContext context,
Properties p)
Create the cache administrator. |
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. |
private ServletCache |
createCache(int scope,
String sessionId)
Create a cache |
static void |
destroyInstance(javax.servlet.ServletContext context)
Shuts down all servlet cache administrators. |
private void |
dispatchScopeEvent(ScopeEventType eventType,
int scope,
Date date,
String origin)
Dispatch a scope event to all registered listeners. |
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 |
static ServletCacheAdministrator |
getInstanceFromKey(javax.servlet.ServletContext context,
String key)
Obtain an instance of the CacheAdministrator for the specified key |
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. |
private void |
initHostDomainInKey()
Set property cache.use.host.domain.in.key=true to add domain information to key generation for hosting multiple sites |
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. |
private static String |
toBase64(byte[] aValue)
Convert a byte array into a Base64 string (as used in mime formats) |
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 |
---|
private static final transient org.apache.commons.logging.Log log
private static final String CACHE_USE_HOST_DOMAIN_KEY
private static final String CACHE_KEY_KEY
private static final String DEFAULT_CACHE_KEY
public static final String SESSION_SCOPE_NAME
public static final String APPLICATION_SCOPE_NAME
private static final String CACHE_ADMINISTRATOR_KEY_SUFFIX
private static final String CACHE_ADMINISTRATORS_KEY
public static final String HASH_KEY_SCOPE
public static final String HASH_KEY_SESSION_ID
public static final String HASH_KEY_CONTEXT_TMPDIR
private static final String FILE_SEPARATOR
private static final char FILE_SEPARATOR_CHAR
private static final short AVERAGE_KEY_LENGTH
private static final String m_strBase64Chars
private Map flushTimes
private transient javax.servlet.ServletContext context
private String cacheKey
private boolean useHostDomainInKey
Constructor Detail |
---|
private ServletCacheAdministrator(javax.servlet.ServletContext context, Properties p)
Method Detail |
---|
public static ServletCacheAdministrator getInstance(javax.servlet.ServletContext context)
context
- The ServletContext that this CacheAdministrator is a Singleton under
public static ServletCacheAdministrator getInstanceFromKey(javax.servlet.ServletContext context, String key)
context
- The ServletContext that this CacheAdministrator is a Singleton underkey
- the cachekey or admincachekey for the CacheAdministrator wanted
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)
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.
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)
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.
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
private static String toBase64(byte[] aValue)
private ServletCache createCache(int scope, String sessionId)
scope
- The cache scopesessionId
- The sessionId for with the cache will be created
private void dispatchScopeEvent(ScopeEventType eventType, int scope, Date date, String origin)
eventType
- The type of eventscope
- Scope that was flushed (Does not apply for FLUSH_ALL event)date
- Date of flushingorigin
- The origin of the eventprivate void initHostDomainInKey()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |