com.jalios.jcms
Class CacheManager

java.lang.Object
  extended by com.jalios.jcms.db.BasicDBListener
      extended by com.jalios.jcms.db.BasicDBListenerStoreListener
          extended by com.jalios.jcms.CacheManager
All Implemented Interfaces:
DBConstants, DBListener, JcmsConstants, PluginComponent, StoreListener, JaliosConstants, Serializable, EventListener, javax.servlet.http.HttpSessionBindingListener

public class CacheManager
extends BasicDBListenerStoreListener
implements javax.servlet.http.HttpSessionBindingListener, JcmsConstants, Serializable

This class manages the cache of content fragements.

Cache entries can be invalidated either manually (see clearContent() method), or when a timeout is reached or when a mutation occurs on a set of (Storable) classes.

Since:
jcms-3.0
Version:
$Revision: 36890 $
Author:
Olivier Dedieu
See Also:
Serialized Form

Nested Class Summary
 class CacheManager.CacheEntry
           
protected  class CacheManager.ServerCacheLRU
          Helper class used to store the LRU collection of server's caches.
 
Field Summary
protected  Channel channel
           
protected  Map<Class<?>,HashSet<String>> classMap
           
protected  Map<String,CacheManager.CacheEntry> contentMap
           
protected  Map<String,CacheManager.ServerCacheLRU> customServerCacheLRUMap
          LRU of the default configuration.
protected  CacheManager.ServerCacheLRU defaultServerCacheLRU
          LRU of the default configuration
protected  boolean isDisabled
           
static String REVISION
           
 
Fields inherited from interface com.jalios.jcms.JcmsConstants
ADATE_SEARCH, ADMIN_NOTES_PROP, ADVANCED_TAB, ARCHIVES_DIR, ASCII_WIDTH, CATEGORY_TAB, CDATE_SEARCH, COMMON_ALARM, CONTENT_TAB, COOKIE_MAX_AGE, CTRL_TOPIC_INTERNAL, CTRL_TOPIC_REF, CTRL_TOPIC_VALUE, CTRL_TOPIC_WRITE, CUSTOM_PROP, DOCCHOOSER_HEIGHT, DOCCHOOSER_WIDTH, DOCS_DIR, EDATE_SEARCH, EMAIL_REGEXP, ERROR_MSG, FORBIDDEN_FILE_ACCESS, FORBIDDEN_REDIRECT, FORCE_REDIRECT, ICON_ARCHIVE, ICON_LOCK, ICON_LOCK_STRONG, ICON_WARN, ICON_WH_BOOK_CLOSED, ICON_WH_BOOK_OPEN, INFORMATION_MSG, JALIOS_JUNIT_PROP, JCMS_CADDY, JCMS_MSG_LIST, JSYNC_DOWNLOAD_DIR, JSYNC_SYNC_ALARM, LOG_FILE, LOG_TOPIC_SECURITY, LOGGER_PROP, LOGGER_XMLPROP, MBR_PHOTO_DIR, MDATE_SEARCH, MONITOR_XML, OP_CREATE, OP_DEEP_COPY, OP_DEEP_DELETE, OP_DELETE, OP_MERGE, OP_UPDATE, PDATE_SEARCH, PHOTO_DIR, PHOTO_ICON, PHOTO_ICON_HEIGHT, PHOTO_ICON_WIDTH, PHOTO_LARGE, PHOTO_LARGE_HEIGHT, PHOTO_LARGE_WIDTH, PHOTO_NORMAL, PHOTO_NORMAL_HEIGHT, PHOTO_NORMAL_WIDTH, PHOTO_SMALL, PHOTO_SMALL_HEIGHT, PHOTO_SMALL_WIDTH, PHOTO_TINY, PHOTO_TINY_HEIGHT, PHOTO_TINY_WIDTH, PREVIOUS_TAB, PRINT_VIEW, PRIVATE_FILE_ACCESS, PUBLIC_FILE_ACCESS, READ_RIGHT_TAB, SDATE_SEARCH, SEARCHENGINE_ALARM, SESSION_AUTHORIZED_FILENAMES_SET, STATS_REPORT_DIR, STATUS_PROP, STORE_XML, TEMPLATE_TAB, THUMBNAIL_LARGE_HEIGHT, THUMBNAIL_LARGE_WIDTH, THUMBNAIL_SMALL_HEIGHT, THUMBNAIL_SMALL_WIDTH, UDATE_SEARCH, UPDATE_RIGHT_TAB, UPLOAD_DIR, URL_REGEXP, WARNING_MSG, WEBAPP_PROP, WFEXPRESS_ALARM, WFREMINDER_ALARM, WORKFLOW_TAB, WORKFLOW_XML
 
Fields inherited from interface com.jalios.util.JaliosConstants
CRLF, MILLIS_IN_ONE_DAY, MILLIS_IN_ONE_HOUR, MILLIS_IN_ONE_MINUTE, MILLIS_IN_ONE_MONTH, MILLIS_IN_ONE_SECOND, MILLIS_IN_ONE_WEEK, MILLIS_IN_ONE_YEAR
 
Fields inherited from interface com.jalios.jcms.db.DBConstants
ALL_CATEGORIES_SET_FIELD, AUTH_GRP_SET_FIELD, AUTH_MBR_SET_FIELD, AUTHOR_ID_FIELD, CATEGORIES_SET_FIELD, CDATE_FIELD, CHANNEL_JCMSDB_PROP, DBDATA_URID, HAS_NO_READ_RIGHTS, HIBERNATE_MAPPING_ADATE, HIBERNATE_MAPPING_AUTHOR, HIBERNATE_MAPPING_CDATE, HIBERNATE_MAPPING_EDATE, HIBERNATE_MAPPING_MDATE, HIBERNATE_MAPPING_PDATE, HIBERNATE_MAPPING_PSTATUS, HIBERNATE_MAPPING_TITLE, HIBERNATE_MAPPING_WORKFLOW_ID, HIBERNATE_MAPPING_WORKSPACE_ID, MDATE_FIELD, PSTATUS_FIELD, ROW_ID_FIELD, SCROLL_FETCH_SIZE, WORKFLOW_ID_FIELD, WORKSPACE_ID_FIELD
 
Constructor Summary
  CacheManager()
          Constructs a new CacheManager
protected CacheManager(boolean failsafeMode)
           
 
Method Summary
 String addEntry(String contentId, javax.servlet.http.HttpSession session, boolean sessionScope, String content, Class<?>[] classes, long timeout, Map<?,?> extraInfoMap, String serverCacheConfig)
          Add a new cache entry
 String buildEntryId(String contentId, String sessionId, String serverCacheConfiguration)
          Build the entry id given the content's id and the associated session id.
 Collection<CacheManager.CacheEntry> getCacheEntries()
          Get all the cache entries.
 CacheManager.CacheEntry getCacheEntry(String id)
          Get the CacheEntry from a given entry's id.
static CacheManager getFailSafeModeInstance()
           
 int getMaxServersCacheNbr()
           
protected  Map<String,String> getServerCacheIdMap(String id)
          Retrieve the server Cache Map to use for the specified cache id
 int getSize()
          Get the size of the cache (ie the count of cache entries).
 void handleCommitUpdate(Storable storable, Storable oldStorable, boolean firstTime)
          This method gets called when after a storable has been updated.
 void handleCreate(Storable storable, boolean firstTime)
          This method gets called when a storable is created.
 void handleDelete(Storable storable, boolean firstTime)
          This method gets called when a storable is deleted.
 void invalidateClass(Class<?> clazz)
          Invalidate the content of all entries bound to the given class
 boolean isCached(String id)
          Check if their is a cache entry associated with the given id.
 boolean isDisabled()
           
 void onPostDelete(DBData data, org.hibernate.event.PostDeleteEvent event, boolean firstTime)
           
 void onPostInsert(DBData data, org.hibernate.event.PostInsertEvent event, boolean firstTime)
           
 void onPostUpdate(DBData data, org.hibernate.event.PostUpdateEvent event, boolean firstTime)
           
 void reinitialize()
          Reinitialize the CacheManager.
 void removeAllEntries()
          Clear all the cache entries.
 void removeAllSessionEntries()
          Clear all the session cache entries.
 void removeEntry(String id)
          Remove a cache entry referenced with is id.
 void removeSessionEntries(javax.servlet.http.HttpSession session)
          Clear all the session cache entries for a given session
 void valueBound(javax.servlet.http.HttpSessionBindingEvent event)
           
 void valueUnbound(javax.servlet.http.HttpSessionBindingEvent event)
           
 
Methods inherited from class com.jalios.jcms.db.BasicDBListenerStoreListener
handlePrepareUpdate
 
Methods inherited from class com.jalios.jcms.db.BasicDBListener
getAdateFromState, getAuthorIdFromState, getCdateFromState, getEdateFromState, getMdateFromState, getPdateFromState, getPrePstatus, getPrePstatus, getPstatusFromState, hasNoChange, hasNoChange, init, onPreUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

isDisabled

protected transient boolean isDisabled

channel

protected transient Channel channel

contentMap

protected final transient Map<String,CacheManager.CacheEntry> contentMap

classMap

protected final transient Map<Class<?>,HashSet<String>> classMap

defaultServerCacheLRU

protected transient CacheManager.ServerCacheLRU defaultServerCacheLRU
LRU of the default configuration


customServerCacheLRUMap

protected transient Map<String,CacheManager.ServerCacheLRU> customServerCacheLRUMap
LRU of the default configuration. Map of custom configuration name to ServerCacheLRU instance.

Constructor Detail

CacheManager

public CacheManager()
Constructs a new CacheManager


CacheManager

protected CacheManager(boolean failsafeMode)
Method Detail

getFailSafeModeInstance

public static CacheManager getFailSafeModeInstance()

reinitialize

public void reinitialize()
Reinitialize the CacheManager. Reload isDisabled and MaxServersCacheNbr values from properties.


isDisabled

public boolean isDisabled()
Returns:
true if the cache manager is disabled.

getMaxServersCacheNbr

public int getMaxServersCacheNbr()
Returns:
the maximum number of server's cache allowed.

getServerCacheIdMap

protected Map<String,String> getServerCacheIdMap(String id)
Retrieve the server Cache Map to use for the specified cache id

Parameters:
id - must not be null
Returns:
the custom cache map to use or the default cache map, never return null

buildEntryId

public String buildEntryId(String contentId,
                           String sessionId,
                           String serverCacheConfiguration)
Build the entry id given the content's id and the associated session id. Given this 2 parameter, the returned id will be always the same.

Parameters:
contentId - the content id
sessionId - the http session id, exclusive with serverCacheConfiguration
serverCacheConfiguration - the custom configuration to use for server configuration, exclusive with sessionId
Returns:
the id to be used for a cache entry.

addEntry

public String addEntry(String contentId,
                       javax.servlet.http.HttpSession session,
                       boolean sessionScope,
                       String content,
                       Class<?>[] classes,
                       long timeout,
                       Map<?,?> extraInfoMap,
                       String serverCacheConfig)
Add a new cache entry

Parameters:
contentId - the id of content
session - the session
sessionScope - should the cache entry be stored for this session
content - the content to be cached
classes - an array of classes to listen. Each time a mutation occurs on a (visible) instance of the classes the content of the cache is cleared.
timeout - the timeout of this entry (in minutes)
extraInfoMap - any contextual data to the cache being created
serverCacheConfig - an optionnal custom server cache configuration to use (use only when sessionScope = false)
Returns:
the id of the entry (concatenation of id and session's id).

isCached

public boolean isCached(String id)
Check if their is a cache entry associated with the given id.

Parameters:
id - the CacheEntry's id
Returns:
true if there is a cache entry associated with this id, false otherwise.

getSize

public int getSize()
Get the size of the cache (ie the count of cache entries).

Returns:
the count of cache entries

getCacheEntries

public Collection<CacheManager.CacheEntry> getCacheEntries()
Get all the cache entries.

Returns:
a NEW collection of CacheEntry

getCacheEntry

public CacheManager.CacheEntry getCacheEntry(String id)
Get the CacheEntry from a given entry's id.

Parameters:
id - the entry's id
Returns:
the CacheEntry bound to the given id

removeEntry

public void removeEntry(String id)
Remove a cache entry referenced with is id.

Parameters:
id - the entry's id

removeAllEntries

public void removeAllEntries()
Clear all the cache entries.


removeAllSessionEntries

public void removeAllSessionEntries()
Clear all the session cache entries.


removeSessionEntries

public void removeSessionEntries(javax.servlet.http.HttpSession session)
Clear all the session cache entries for a given session

Parameters:
session - the session
Since:
jcms-4.0

invalidateClass

public void invalidateClass(Class<?> clazz)
Invalidate the content of all entries bound to the given class

Parameters:
clazz - the class for which the entries must be cleared

handleCreate

public void handleCreate(Storable storable,
                         boolean firstTime)
Description copied from interface: StoreListener
This method gets called when a storable is created.

Specified by:
handleCreate in interface StoreListener
Overrides:
handleCreate in class BasicDBListenerStoreListener
Parameters:
storable - the storable
firstTime - true if it is the first time this operation is processed
See Also:
StoreListener.handleCreate(Storable, boolean)

handleCommitUpdate

public void handleCommitUpdate(Storable storable,
                               Storable oldStorable,
                               boolean firstTime)
Description copied from interface: StoreListener
This method gets called when after a storable has been updated.

Specified by:
handleCommitUpdate in interface StoreListener
Overrides:
handleCommitUpdate in class BasicDBListenerStoreListener
Parameters:
storable - the storable, this instance is the object that was created at first and that will be stored in jcms until deletion of the storable with this ID. You should always manipulate this object if you maintain any index.
oldStorable - the previous version of the storable, it is a clone, do not use in any index, it should only be used to access old values.
firstTime - true if it is the first time this operation is processed
See Also:
StoreListener.handleCommitUpdate(Storable, Storable, boolean)

handleDelete

public void handleDelete(Storable storable,
                         boolean firstTime)
Description copied from interface: StoreListener
This method gets called when a storable is deleted.

Specified by:
handleDelete in interface StoreListener
Overrides:
handleDelete in class BasicDBListenerStoreListener
Parameters:
storable - the storable
firstTime - true if it is the first time this operation is processed
See Also:
StoreListener.handleDelete(Storable, boolean)

onPostInsert

public void onPostInsert(DBData data,
                         org.hibernate.event.PostInsertEvent event,
                         boolean firstTime)
Specified by:
onPostInsert in interface DBListener
Overrides:
onPostInsert in class BasicDBListener
See Also:
DBListener.onPostInsert(DBData, PostInsertEvent, boolean)

onPostUpdate

public void onPostUpdate(DBData data,
                         org.hibernate.event.PostUpdateEvent event,
                         boolean firstTime)
Specified by:
onPostUpdate in interface DBListener
Overrides:
onPostUpdate in class BasicDBListener
See Also:
DBListener.onPostUpdate(DBData, PostUpdateEvent, boolean)

onPostDelete

public void onPostDelete(DBData data,
                         org.hibernate.event.PostDeleteEvent event,
                         boolean firstTime)
Specified by:
onPostDelete in interface DBListener
Overrides:
onPostDelete in class BasicDBListener
See Also:
DBListener.onPostDelete(DBData, PostDeleteEvent, boolean)

valueBound

public void valueBound(javax.servlet.http.HttpSessionBindingEvent event)
Specified by:
valueBound in interface javax.servlet.http.HttpSessionBindingListener

valueUnbound

public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent event)
Specified by:
valueUnbound in interface javax.servlet.http.HttpSessionBindingListener


Copyright © 2001-2010 Jalios SA. All Rights Reserved.