com.opencms.flex.cache
Class CmsFlexCache

java.lang.Object
  |
  +--com.opencms.flex.cache.CmsFlexCache
All Implemented Interfaces:
I_CmsEventListener

public class CmsFlexCache
extends Object
implements I_CmsEventListener

This class implements the FlexCache.

The data structure used is a two-level hashtable. This is optimized for the structure of the keys that are used to describe the caching behaviour of the entries. The first hash-level is calculated from the resource name, i.e. the name of the resource as it is referred to in the VFS of OpenCms. A suffix [online] or [offline] is appended to te resource name to distinguish between the online and offline projects of OpenCms. The second hash-level is calculated from the cache-key of the resource, which also is a String representing the specifc variation of the cached entry.

Entries in the first level of the cache are of type CmsFlexCacheVariation, which is a sub-class of CmsFlexCache. This class is a simple data type that contains of a Map of CmsFlexCacheEntries, with variations - Strings as keys.

Here's a short summary of used terms:

Currenty the whole cache is flushed if something is published. Implement partial cache flushing, i.e. remove only changed elements at publish or change event (in case of offline resources).

Version:
$Revision: 1.17 $
Author:
Alexander Kandzior (a.kandzior@alkacon.com), Thomas Weckert (t.weckert@alkacon.com)
See Also:
CmsFlexCacheKey, CmsFlexCacheEntry, CmsFlexLruCache, I_CmsFlexLruCacheObject

Field Summary
static String C_CACHE_OFFLINESUFFIX
          Suffix to append to online cache entries
static String C_CACHE_ONLINESUFFIX
          Suffix to append to online cache entries
static int C_CLEAR_ALL
          Static ints to trigger clearcache events
static int C_CLEAR_ENTRIES
           
static int C_CLEAR_OFFLINE_ALL
           
static int C_CLEAR_OFFLINE_ENTRIES
           
static int C_CLEAR_ONLINE_ALL
           
static int C_CLEAR_ONLINE_ENTRIES
           
static int C_INITIAL_CAPACITY_CACHE
          Initial Cache size, this should be a power of 2 because of the Java collections implementation
static int C_INITIAL_CAPACITY_VARIATIONS
          Initial size for variation lists, should be a power of 2
 
Fields inherited from interface com.opencms.flex.I_CmsEventListener
EVENT_CLEAR_CACHES, EVENT_FLEX_CACHE_CLEAR, EVENT_FLEX_CLUSTER_CHECK_SOURCE, EVENT_FLEX_CLUSTER_HOOK, EVENT_FLEX_PURGE_JSP_REPOSITORY, EVENT_LOGIN_USER, EVENT_PUBLISH_BO_RESOURCE, EVENT_PUBLISH_PROJECT, EVENT_PUBLISH_RESOURCE, EVENT_STATIC_EXPORT
 
Constructor Summary
CmsFlexCache(OpenCms openCms)
          Constructor for class CmsFlexCache.
 
Method Summary
 boolean cacheOffline()
          Indicates if offline project resources are cached.
 void cmsEvent(CmsEvent event)
          Implements the CmsEvent interface, the FlexCache uses the events to clear itself in case a project is published.
protected  void finalize()
          Clears the cache for finalization.
 CmsFlexCacheKey getCachedKey(String key, CmsObject cms)
          Returns the CmsFlexCacheKey data structure for a given key (i.e. resource name).
 Set getCachedResources(CmsObject cms)
          Returns a set of all cached resource names.
 Set getCachedVariations(String key, CmsObject cms)
          Returns all variations in the cache for a given resource name.
 CmsFlexLruCache getEntryLruCache()
          Returns the LRU cache where the CacheEntries are cached.
 boolean isEnabled()
          Indicates if the cache is enabled (i.e. actually caching entries) or not.
 int keySize()
          Returns the total number of cached resource keys.
 int size()
          Returns the total number of entries in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

C_INITIAL_CAPACITY_CACHE

public static final int C_INITIAL_CAPACITY_CACHE
Initial Cache size, this should be a power of 2 because of the Java collections implementation

See Also:
Constant Field Values

C_INITIAL_CAPACITY_VARIATIONS

public static final int C_INITIAL_CAPACITY_VARIATIONS
Initial size for variation lists, should be a power of 2

See Also:
Constant Field Values

C_CACHE_ONLINESUFFIX

public static String C_CACHE_ONLINESUFFIX
Suffix to append to online cache entries


C_CACHE_OFFLINESUFFIX

public static String C_CACHE_OFFLINESUFFIX
Suffix to append to online cache entries


C_CLEAR_ALL

public static final int C_CLEAR_ALL
Static ints to trigger clearcache events

See Also:
Constant Field Values

C_CLEAR_ENTRIES

public static final int C_CLEAR_ENTRIES
See Also:
Constant Field Values

C_CLEAR_ONLINE_ALL

public static final int C_CLEAR_ONLINE_ALL
See Also:
Constant Field Values

C_CLEAR_ONLINE_ENTRIES

public static final int C_CLEAR_ONLINE_ENTRIES
See Also:
Constant Field Values

C_CLEAR_OFFLINE_ALL

public static final int C_CLEAR_OFFLINE_ALL
See Also:
Constant Field Values

C_CLEAR_OFFLINE_ENTRIES

public static final int C_CLEAR_OFFLINE_ENTRIES
See Also:
Constant Field Values
Constructor Detail

CmsFlexCache

public CmsFlexCache(OpenCms openCms)
Constructor for class CmsFlexCache.

The parameter "enabled" is used to control if the cache is actually on or off. Even if you don't need the cache, you still have to create an instance of it with enabled=false. This is because you need some of the FlexCache data structures for JSP inclusion buffering.

Parameters:
openCms - the OpenCms instance
Method Detail

finalize

protected void finalize()
                 throws Throwable
Clears the cache for finalization.

Overrides:
finalize in class Object
Throwable

isEnabled

public boolean isEnabled()
Indicates if the cache is enabled (i.e. actually caching entries) or not.

Returns:
true if the cache is enabled, false if not

cacheOffline

public boolean cacheOffline()
Indicates if offline project resources are cached.

Returns:
true if offline projects are cached, false if not

getCachedResources

public Set getCachedResources(CmsObject cms)
Returns a set of all cached resource names. Usefull if you want to show a list of all cached resources, like on the FlexCache administration page.

Only users with administrator permissions are allowed to perform this operation.

Parameters:
cms - the CmsObject used for user authorization
Returns:
a Set of cached resource names (which are of type String)

getCachedVariations

public Set getCachedVariations(String key,
                               CmsObject cms)
Returns all variations in the cache for a given resource name. The variations are of type String.

Usefull if you want to show a list of all cached entry - variations, like on the FlexCache administration page.

Only users with administrator permissions are allowed to perform this operation.

Parameters:
key - the resource name for which to look up the variations for
cms - the CmsObject used for user authorization
Returns:
a Set of cached variations (which are of type String)

getCachedKey

public CmsFlexCacheKey getCachedKey(String key,
                                    CmsObject cms)
Returns the CmsFlexCacheKey data structure for a given key (i.e. resource name).

Usefull if you want to show the cache key for a resources, like on the FlexCache administration page.

Only users with administrator permissions are allowed to perform this operation.

Parameters:
key - the resource name for which to look up the variation for
cms - the CmsObject used for user authorization
Returns:
the CmsFlexCacheKey data structure found for the resource

size

public int size()
Returns the total number of entries in the cache.

Returns:
the number of entries in the cache

keySize

public int keySize()
Returns the total number of cached resource keys.

Returns:
the number of resource keys in the cache

cmsEvent

public void cmsEvent(CmsEvent event)
Implements the CmsEvent interface, the FlexCache uses the events to clear itself in case a project is published.

Specified by:
cmsEvent in interface I_CmsEventListener
Parameters:
event - CmsEvent that has occurred

getEntryLruCache

public CmsFlexLruCache getEntryLruCache()
Returns the LRU cache where the CacheEntries are cached.

Returns:
the LRU cache where the CacheEntries are cached