Class CacheManager

    • Field Detail


        public static final java.lang.String ATTR_CACHE_PREFIX
        since 10.0.7 / JCMS-9927
        See Also:
        Constant Field Values

        public static final java.lang.String SESSION_SEPARATOR
        See Also:
        Constant Field Values
      • defaultServerCacheLRU

        protected transient com.jalios.jcms.CacheManager.ServerCacheLRU defaultServerCacheLRU
        LRU of the default configuration
      • customServerCacheLRUMap

        protected transient java.util.Map<java.lang.String,​com.jalios.jcms.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()
        true if the cache manager is disabled.
      • getMaxServersCacheNbr

        public int getMaxServersCacheNbr()
        the maximum number of server's cache allowed.
      • getServerCacheIdMap

        protected java.util.Map<java.lang.String,​java.lang.String> getServerCacheIdMap​(java.lang.String id)
        Retrieve the server Cache Map to use for the specified cache id
        id - must not be null
        the custom cache map to use or the default cache map, never return null
      • buildEntryId

        public java.lang.String buildEntryId​(java.lang.String contentId,
                                             java.lang.String sessionId,
                                             java.lang.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.
        contentId - the content id
        sessionId - the http session id, exclusive with serverCacheConfiguration
        serverCacheConfiguration - the custom configuration to use for server configuration, exclusive with sessionId
        the id to be used for a cache entry.
      • addEntry

        public java.lang.String addEntry​(java.lang.String contentId,
                                         javax.servlet.http.HttpSession session,
                                         boolean sessionScope,
                                         java.lang.String content,
                                         java.lang.Class<?>[] classes,
                                         long timeout,
                                         java.util.Map<?,​?> extraInfoMap,
                                         java.lang.String serverCacheConfig)
        Add a new cache entry
        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 millis)
        extraInfoMap - any contextual data to the cache being created
        serverCacheConfig - an optional custom server cache configuration to use (use only when sessionScope = false)
        the id of the entry (concatenation of id and session's id).
      • isCached

        public boolean isCached​(java.lang.String id)
        Check if their is a cache entry associated with the given id.
        id - the CacheEntry's id
        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).
        the count of cache entries
      • getCacheEntries

        public java.util.Collection<CacheManager.CacheEntry> getCacheEntries()
        Get all the cache entries.
        a NEW collection of CacheEntry
      • getCacheEntry

        public CacheManager.CacheEntry getCacheEntry​(java.lang.String id)
        Get the CacheEntry from a given entry's id.
        id - the entry's id
        the CacheEntry bound to the given id
      • removeEntry

        public void removeEntry​(java.lang.String id)
        Remove a cache entry referenced with is id.
        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
        session - the session
      • invalidateClass

        public void invalidateClass​(java.lang.Class<?> clazz)
        Invalidate the content of all entries bound to the given class
        clazz - the class for which the entries must be cleared
      • 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
        handleCommitUpdate in class BasicDBListenerStoreListener
        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)
      • onPostDelete

        public void onPostDelete​(DBData data,
                                 org.hibernate.event.PostDeleteEvent event,
                                 boolean firstTime)
        Description copied from interface: DBListener
        This method is called after a DBData has been deleted.
        Specified by:
        onPostDelete in interface DBListener
        onPostDelete in class BasicDBListener
        data - the deleted DBData. WARNING! In a JSync Cluster, when firstTime is false, this data will be null. In this case, to get information about this deleted data, you must use the event and in particular event.getId(), which returns the JPlatform ID of the data, and event.getDeletedState() which returns the attributes of the data.
        event - the event
        firstTime - true on the JSync replica on which the operation took place and false on the other replicas.
        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