Class CmsFlexCache
- java.lang.Object
-
- org.opencms.flex.CmsFlexCache
-
- All Implemented Interfaces:
I_CmsEventListener
public class CmsFlexCache extends java.lang.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. 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.
A suffix [online] or [offline] is appended to te resource name to distinguish between the online and offline projects of OpenCms. Also, for support of JSP based workplace pages, a suffix [workplace] is appended. The same cached workplace pages are used both in the online and all offline projects.
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:
- key: A combination of a resource name and a variation. The data structure used is CmsFlexCacheKey.
- resource: A String with the resource name and an appended [online] of [offline] suffix.
- variation: A String describing a variation of a cached entry in the CmsFlexCache language.
- entry: A CmsFlexCacheEntry data structure which is describes a cached OpenCms resource. For every entry a key is saved which contains the resource name and the variation.
I_CmsEventListener.EVENT_PUBLISH_PROJECT
orI_CmsEventListener.EVENT_CLEAR_CACHES
is caught.- Since:
- 6.0.0
- See Also:
CmsFlexCacheKey
,CmsFlexCacheEntry
,CmsLruCache
,I_CmsLruCacheObject
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsFlexCache.CmsFlexCacheVariation
A simple data container class for the FlexCache variations.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CACHE_ACTION
Constant for distinguish cache action.static java.lang.String
CACHE_OFFLINESUFFIX
Suffix to append to online cache entries.static java.lang.String
CACHE_ONLINESUFFIX
Suffix to append to online cache entries.static int
CLEAR_ALL
Trigger for clearcache event: Clear complete cache.static int
CLEAR_ENTRIES
Trigger for clearcache event: Clear only entries.static int
CLEAR_OFFLINE_ALL
Trigger for clearcache event: Clear complete offine cache.static int
CLEAR_OFFLINE_ENTRIES
Trigger for clearcache event: Clear only offline entries.static int
CLEAR_ONLINE_ALL
Trigger for clearcache event: Clear complete online cache.static int
CLEAR_ONLINE_ENTRIES
Trigger for clearcache event: Clear only online entries.static java.lang.String
CONFIG_PATH
The configuration for the Flex cache buckets.static int
INITIAL_CAPACITY_CACHE
Initial cache size, this should be a power of 2 because of the Java collections implementation.static int
INITIAL_CAPACITY_VARIATIONS
Initial size for variation lists, should be a power of 2.protected CmsLruCache
m_variationCache
The LRU cache to organize the cached entries.static java.lang.String
REPOSITORY_OFFLINE
Offline repository constant.static java.lang.String
REPOSITORY_ONLINE
Online repository constant.-
Fields inherited from interface org.opencms.main.I_CmsEventListener
EVENT_BEFORE_PUBLISH_PROJECT, EVENT_CLEAR_CACHES, EVENT_CLEAR_OFFLINE_CACHES, EVENT_CLEAR_ONLINE_CACHES, EVENT_CLEAR_PRINCIPAL_CACHES, EVENT_FLEX_CACHE_CLEAR, EVENT_FLEX_PURGE_JSP_REPOSITORY, EVENT_FULLSTATIC_EXPORT, EVENT_GROUP_MODIFIED, EVENT_LOGIN_USER, EVENT_OU_MODIFIED, EVENT_PROJECT_MODIFIED, EVENT_PROPERTY_DEFINITION_CREATED, EVENT_PROPERTY_DEFINITION_MODIFIED, EVENT_PROPERTY_MODIFIED, EVENT_PUBLISH_PROJECT, EVENT_REBUILD_SEARCHINDEXES, EVENT_REINDEX_OFFLINE, EVENT_REINDEX_ONLINE, EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, EVENT_RESOURCE_COPIED, EVENT_RESOURCE_CREATED, EVENT_RESOURCE_DELETED, EVENT_RESOURCE_MODIFIED, EVENT_RESOURCE_MOVED, EVENT_RESOURCES_AND_PROPERTIES_MODIFIED, EVENT_RESOURCES_MODIFIED, EVENT_SITEMAP_CHANGED, EVENT_UPDATE_EXPORTS, EVENT_USER_MODIFIED, KEY_CHANGE, KEY_DBCONTEXT, KEY_GROUP_ID, KEY_GROUP_NAME, KEY_INDEX_NAMES, KEY_IS_ONLINE, KEY_OU_ID, KEY_OU_NAME, KEY_PROJECTID, KEY_PUBLISHID, KEY_PUBLISHLIST, KEY_REINDEX_RELATED, KEY_REPORT, KEY_RESOURCE, KEY_RESOURCES, KEY_SKIPINDEX, KEY_USER_ACTION, KEY_USER_CHANGES, KEY_USER_ID, KEY_USER_NAME, LISTENERS_FOR_ALL_EVENTS, VALUE_CREATE_SIBLING, VALUE_GROUP_MODIFIED_ACTION_CREATE, VALUE_GROUP_MODIFIED_ACTION_DELETE, VALUE_GROUP_MODIFIED_ACTION_WRITE, VALUE_OU_MODIFIED_ACTION_CREATE, VALUE_OU_MODIFIED_ACTION_DELETE, VALUE_USER_MODIFIED_ACTION_ADD_USER_TO_GROUP, VALUE_USER_MODIFIED_ACTION_CREATE_USER, VALUE_USER_MODIFIED_ACTION_DELETE_USER, VALUE_USER_MODIFIED_ACTION_REMOVE_USER_FROM_GROUP, VALUE_USER_MODIFIED_ACTION_RESET_PASSWORD, VALUE_USER_MODIFIED_ACTION_SET_OU, VALUE_USER_MODIFIED_ACTION_WRITE_USER
-
-
Constructor Summary
Constructors Constructor Description CmsFlexCache(CmsFlexCacheConfiguration configuration)
Constructor for class CmsFlexCache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
dumpKeys(java.lang.StringBuffer buffer)
Dumps keys and variations to a string buffer, for debug purposes.CmsFlexCacheKey
getCachedKey(java.lang.String key, CmsObject cms)
Returns the CmsFlexCacheKey data structure for a given key (i.e.java.util.Set<java.lang.String>
getCachedResources(CmsObject cms)
Returns a set of all cached resource names.java.util.Set<java.lang.String>
getCachedVariations(java.lang.String key, CmsObject cms)
Returns all variations in the cache for a given resource name.CmsLruCache
getEntryLruCache()
Returns the LRU cache where the CacheEntries are cached.void
initializeCms(CmsObject adminCms)
Initializes the flex cache.boolean
isEnabled()
Indicates if the cache is enabled (i.e.int
keySize()
Returns the total number of cached resource keys.int
size()
Returns the total number of entries in the cache.
-
-
-
Field Detail
-
CACHE_ACTION
public static final java.lang.String CACHE_ACTION
Constant for distinguish cache action.- See Also:
- Constant Field Values
-
CACHE_OFFLINESUFFIX
public static final java.lang.String CACHE_OFFLINESUFFIX
Suffix to append to online cache entries.- See Also:
- Constant Field Values
-
CACHE_ONLINESUFFIX
public static final java.lang.String CACHE_ONLINESUFFIX
Suffix to append to online cache entries.- See Also:
- Constant Field Values
-
CLEAR_ALL
public static final int CLEAR_ALL
Trigger for clearcache event: Clear complete cache.- See Also:
- Constant Field Values
-
CLEAR_ENTRIES
public static final int CLEAR_ENTRIES
Trigger for clearcache event: Clear only entries.- See Also:
- Constant Field Values
-
CLEAR_OFFLINE_ALL
public static final int CLEAR_OFFLINE_ALL
Trigger for clearcache event: Clear complete offine cache.- See Also:
- Constant Field Values
-
CLEAR_OFFLINE_ENTRIES
public static final int CLEAR_OFFLINE_ENTRIES
Trigger for clearcache event: Clear only offline entries.- See Also:
- Constant Field Values
-
CLEAR_ONLINE_ALL
public static final int CLEAR_ONLINE_ALL
Trigger for clearcache event: Clear complete online cache.- See Also:
- Constant Field Values
-
CLEAR_ONLINE_ENTRIES
public static final int CLEAR_ONLINE_ENTRIES
Trigger for clearcache event: Clear only online entries.- See Also:
- Constant Field Values
-
CONFIG_PATH
public static final java.lang.String CONFIG_PATH
The configuration for the Flex cache buckets.- See Also:
- Constant Field Values
-
INITIAL_CAPACITY_CACHE
public static final int INITIAL_CAPACITY_CACHE
Initial cache size, this should be a power of 2 because of the Java collections implementation.- See Also:
- Constant Field Values
-
INITIAL_CAPACITY_VARIATIONS
public static final int INITIAL_CAPACITY_VARIATIONS
Initial size for variation lists, should be a power of 2.- See Also:
- Constant Field Values
-
REPOSITORY_OFFLINE
public static final java.lang.String REPOSITORY_OFFLINE
Offline repository constant.- See Also:
- Constant Field Values
-
REPOSITORY_ONLINE
public static final java.lang.String REPOSITORY_ONLINE
Online repository constant.- See Also:
- Constant Field Values
-
m_variationCache
protected CmsLruCache m_variationCache
The LRU cache to organize the cached entries.
-
-
Constructor Detail
-
CmsFlexCache
public CmsFlexCache(CmsFlexCacheConfiguration configuration)
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:
configuration
- the flex cache configuration
-
-
Method Detail
-
cacheOffline
public boolean cacheOffline()
Indicates if offline project resources are cached.- Returns:
- true if offline projects are cached, false if not
-
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 interfaceI_CmsEventListener
- Parameters:
event
- CmsEvent that has occurred
-
dumpKeys
public void dumpKeys(java.lang.StringBuffer buffer)
Dumps keys and variations to a string buffer, for debug purposes.- Parameters:
buffer
- the buffer to which the key information should be written
-
getCachedKey
public CmsFlexCacheKey getCachedKey(java.lang.String key, CmsObject cms)
Returns the CmsFlexCacheKey data structure for a given key (i.e. resource name).Useful 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 forcms
- the CmsObject used for user authorization- Returns:
- the CmsFlexCacheKey data structure found for the resource
-
getCachedResources
public java.util.Set<java.lang.String> getCachedResources(CmsObject cms)
Returns a set of all cached resource names.Useful 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 java.util.Set<java.lang.String> getCachedVariations(java.lang.String key, CmsObject cms)
Returns all variations in the cache for a given resource name. The variations are of type String.Useful 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 forcms
- the CmsObject used for user authorization- Returns:
- a Set of cached variations (which are of type String)
-
getEntryLruCache
public CmsLruCache getEntryLruCache()
Returns the LRU cache where the CacheEntries are cached.- Returns:
- the LRU cache where the CacheEntries are cached
-
initializeCms
public void initializeCms(CmsObject adminCms)
Initializes the flex cache.- Parameters:
adminCms
- a CMS context with admin privileges
-
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
-
keySize
public int keySize()
Returns the total number of cached resource keys.- Returns:
- the number of resource keys in the cache
-
size
public int size()
Returns the total number of entries in the cache.- Returns:
- the number of entries in the cache
-
-