Class CacheManager
- java.lang.Object
-
- org.pentaho.platform.plugin.services.cache.CacheManager
-
- All Implemented Interfaces:
org.pentaho.platform.api.engine.ICacheManager,org.pentaho.platform.api.engine.ILogoutListener
public class CacheManager extends Object implements org.pentaho.platform.api.engine.ICacheManager
This class provides an access point for pluggable caching mechanisms. Right now, it only supports the caching mechanisms implemented inorg.hibernate.cache.To use the cache manager, you need to include the following information in your
pentaho.xml.<cache-provider> <class>org.hibernate.cache.xxxxxxxx</class> <region>pentahoCache</region> <properties> <property name="someProperty">someValue</property> </properties> </cache-provider>The specified class must implement the
org.hibernate.cache.CacheProviderinterface.Each implementation of the
org.hibernate.cache.CacheProviderhas slightly different requirements with respect to the required input parameters - so, please see the classes in that package for more information (available from the Sourceforge Hibernate project). Also, some cache providers (notably theorg.hibernate.cache.EhCacheProvider) completely ignore the passed in properties, and only configure themselves by locating a configuration file (e.g. ehcache.xml) on the classpath.The cache manager supports session-based caching (that is, caching of data that is user-specific) as well as global-based caching (that is, caching of data that is system-wide). To differentiate between session-based and global-based caching, there are different methods that get called depending upon the storage type.
Data that is cached for user sessions require an
IPentahoSessionobject to be passed in. The cache manager uses theIPentahoSession.getId()to classify saved objects underneath a specific user session. No information is actually stored in the user session object. For an example of this, see
putInSessionCache(IPentahoSession session, String key, Object value)Data that is server-wide (i.e. global) uses different methods for storage/retrieval/management. For an example of this, see
getFromGlobalCache(Object key)Example Usage:
String globalCachable = "String to cache"; String globalCacheKey = "StringKey"; CacheManager cacheManager = PentahoSystem.getCacheManager(); cacheManager.putInGlobalCache( globalCacheKey, globalCachable );
Important Considerations
- Most caches require objects that go into the cache as well as their respective object key implement Serializable. It is a safe assumption that both the Key and the Value should implement Serializable.
- Some caches are read-only. Other caches are read-write. What does this mean? It means that once you put an object in the cache, you can't put an object into the cache with the same key. You'd need to remove it first
- Author:
- mbatchel
- See Also:
CacheProvider,Cache
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.Loglogger
-
Constructor Summary
Constructors Constructor Description CacheManager()The constructor performs the following tasks:
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddCacheRegion(String region)booleanaddCacheRegion(String region, Properties cacheProperties)booleanaddCacheRegion(String region, org.hibernate.cache.Cache cache)booleancacheEnabled()booleancacheEnabled(String region)voidcacheStop()voidclearCache()voidclearRegionCache(String region)SetgetAllEntriesFromRegionCache(String region)SetgetAllKeysFromRegionCache(String region)ListgetAllValuesFromRegionCache(String region)protected org.hibernate.cache.CacheProvidergetCacheProvider()Returns the underlying cache provider (implementsorg.hibernate.cache.CacheProviderlonggetElementCountInGlobalCache()longgetElementCountInRegionCache(String region)longgetElementCountInSessionCache()ObjectgetFromGlobalCache(Object key)ObjectgetFromRegionCache(String region, Object key)ObjectgetFromSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key)voidkillSessionCache(org.pentaho.platform.api.engine.IPentahoSession session)voidkillSessionCaches()voidonLogout(org.pentaho.platform.api.engine.IPentahoSession session)voidputInGlobalCache(Object key, Object value)voidputInRegionCache(String region, Object key, Object value)voidputInSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key, Object value)voidremoveFromGlobalCache(Object key)voidremoveFromRegionCache(String region, Object key)voidremoveFromSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key)voidremoveRegionCache(String region)protected voidsetupCacheProvider(Properties cacheProperties)
-
-
-
Constructor Detail
-
CacheManager
public CacheManager()
The constructor performs the following tasks:- Gets the Hitachi Vantara System Settings
- Reads the
cache-provider/classelement. - Reads the
cache-provider/regionelement. - Reads in any properties under
cache-provider/properties/* - Attempts to instance the cache provider classes specified
- Starts the cache (see the
org.hibernate.cache.CacheProviderinterface) - Calls the buildCache method (see the
org.hibernate.cache.CacheProviderinterface)
-
-
Method Detail
-
setupCacheProvider
protected void setupCacheProvider(Properties cacheProperties)
-
cacheStop
public void cacheStop()
- Specified by:
cacheStopin interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getCacheProvider
protected org.hibernate.cache.CacheProvider getCacheProvider()
Returns the underlying cache provider (implementsorg.hibernate.cache.CacheProvider- Returns:
- cacheProvider.
-
cacheEnabled
public boolean cacheEnabled(String region)
- Specified by:
cacheEnabledin interfaceorg.pentaho.platform.api.engine.ICacheManager
-
onLogout
public void onLogout(org.pentaho.platform.api.engine.IPentahoSession session)
- Specified by:
onLogoutin interfaceorg.pentaho.platform.api.engine.ICacheManager- Specified by:
onLogoutin interfaceorg.pentaho.platform.api.engine.ILogoutListener
-
addCacheRegion
public boolean addCacheRegion(String region, Properties cacheProperties)
- Specified by:
addCacheRegionin interfaceorg.pentaho.platform.api.engine.ICacheManager
-
addCacheRegion
public boolean addCacheRegion(String region)
- Specified by:
addCacheRegionin interfaceorg.pentaho.platform.api.engine.ICacheManager
-
addCacheRegion
public boolean addCacheRegion(String region, org.hibernate.cache.Cache cache)
-
clearRegionCache
public void clearRegionCache(String region)
- Specified by:
clearRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeRegionCache
public void removeRegionCache(String region)
- Specified by:
removeRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
putInRegionCache
public void putInRegionCache(String region, Object key, Object value)
- Specified by:
putInRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getFromRegionCache
public Object getFromRegionCache(String region, Object key)
- Specified by:
getFromRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getAllValuesFromRegionCache
public List getAllValuesFromRegionCache(String region)
- Specified by:
getAllValuesFromRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getAllKeysFromRegionCache
public Set getAllKeysFromRegionCache(String region)
- Specified by:
getAllKeysFromRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getAllEntriesFromRegionCache
public Set getAllEntriesFromRegionCache(String region)
- Specified by:
getAllEntriesFromRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeFromRegionCache
public void removeFromRegionCache(String region, Object key)
- Specified by:
removeFromRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
cacheEnabled
public boolean cacheEnabled()
- Specified by:
cacheEnabledin interfaceorg.pentaho.platform.api.engine.ICacheManager
-
clearCache
public void clearCache()
- Specified by:
clearCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getFromGlobalCache
public Object getFromGlobalCache(Object key)
- Specified by:
getFromGlobalCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getFromSessionCache
public Object getFromSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key)
- Specified by:
getFromSessionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
killSessionCache
public void killSessionCache(org.pentaho.platform.api.engine.IPentahoSession session)
- Specified by:
killSessionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
killSessionCaches
public void killSessionCaches()
- Specified by:
killSessionCachesin interfaceorg.pentaho.platform.api.engine.ICacheManager
-
putInGlobalCache
public void putInGlobalCache(Object key, Object value)
- Specified by:
putInGlobalCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
putInSessionCache
public void putInSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key, Object value)- Specified by:
putInSessionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeFromGlobalCache
public void removeFromGlobalCache(Object key)
- Specified by:
removeFromGlobalCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeFromSessionCache
public void removeFromSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key)- Specified by:
removeFromSessionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getElementCountInRegionCache
public long getElementCountInRegionCache(String region)
- Specified by:
getElementCountInRegionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getElementCountInSessionCache
public long getElementCountInSessionCache()
- Specified by:
getElementCountInSessionCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getElementCountInGlobalCache
public long getElementCountInGlobalCache()
- Specified by:
getElementCountInGlobalCachein interfaceorg.pentaho.platform.api.engine.ICacheManager
-
-