com.opensymphony.oscache.web
Class ServletCache

java.lang.Object
  extended by com.opensymphony.oscache.base.Cache
      extended by com.opensymphony.oscache.web.ServletCache
All Implemented Interfaces:
Serializable, EventListener, HttpSessionBindingListener

public final class ServletCache
extends Cache
implements HttpSessionBindingListener, Serializable

A simple extension of Cache that implements a session binding listener, and deletes it's entries when unbound

Version:
$Revision: 339 $
Author:
Mike Cannon-Brookes, Todd Gochenour, Francois Beauregard
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.opensymphony.oscache.base.Cache
listenerList, NESTED_EVENT
 
Constructor Summary
ServletCache(ServletCacheAdministrator admin, int scope)
          Create a new ServletCache
ServletCache(ServletCacheAdministrator admin, String algorithmClass, int limit, int scope)
          Create a new Cache
 
Method Summary
 int getScope()
          Get the cache scope
protected  boolean isStale(CacheEntry cacheEntry, int refreshPeriod, String cronExpiry)
          Indicates whether or not the cache entry is stale.
 void valueBound(HttpSessionBindingEvent event)
          When this Cache is bound to the session, do nothing.
 void valueUnbound(HttpSessionBindingEvent event)
          When the users's session ends, all listeners are finalized and the session cache directory is deleted from disk.
 
Methods inherited from class com.opensymphony.oscache.base.Cache
addCacheEventListener, addCacheEventListener, cancelUpdate, clear, completeUpdate, flushAll, flushAll, flushEntry, flushEntry, flushGroup, flushGroup, flushPattern, flushPattern, getCacheEntry, getCacheEventListenerList, getCapacity, getFromCache, getFromCache, getFromCache, getNbEntries, getNbUpdateState, getPersistenceListener, getSize, getUpdateState, isFlushed, putInCache, putInCache, putInCache, putInCache, releaseUpdateState, removeCacheEventListener, removeCacheEventListener, removeEntry, removeEntry, setCapacity, setPersistenceListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletCache

public ServletCache(ServletCacheAdministrator admin,
                    int scope)
Create a new ServletCache

Parameters:
admin - The ServletCacheAdministrator to administer this ServletCache.
scope - The scope of all entries in this hashmap

ServletCache

public ServletCache(ServletCacheAdministrator admin,
                    String algorithmClass,
                    int limit,
                    int scope)
Create a new Cache

Parameters:
admin - The CacheAdministrator to administer this Cache.
algorithmClass - The class that implement an algorithm
limit - The maximum cache size in number of entries
scope - The cache scope
Method Detail

getScope

public int getScope()
Get the cache scope

Returns:
The cache scope

valueBound

public void valueBound(HttpSessionBindingEvent event)
When this Cache is bound to the session, do nothing.

Specified by:
valueBound in interface HttpSessionBindingListener
Parameters:
event - The SessionBindingEvent.

valueUnbound

public void valueUnbound(HttpSessionBindingEvent event)
When the users's session ends, all listeners are finalized and the session cache directory is deleted from disk.

Specified by:
valueUnbound in interface HttpSessionBindingListener
Parameters:
event - The event that triggered this unbinding.

isStale

protected boolean isStale(CacheEntry cacheEntry,
                          int refreshPeriod,
                          String cronExpiry)
Indicates whether or not the cache entry is stale. This overrides the Cache.isStale(CacheEntry, int, String) method to take into account any flushing that may have been applied to the scope that this cache belongs to.

Overrides:
isStale in class Cache
Parameters:
cacheEntry - The cache entry to test the freshness of.
refreshPeriod - The maximum allowable age of the entry, in seconds.
cronExpiry - A cron expression that defines fixed expiry dates and/or times for this cache entry.
Returns:
true if the entry is stale, false otherwise.

OSCache Project Page