Class CacheManager
- All Implemented Interfaces:
org.pentaho.platform.api.engine.ICacheManager
,org.pentaho.platform.api.engine.ILogoutListener
org.hibernate.cache
for Timestamp Regions.
To use the cache manager, you need to include the following information in your pentaho.xml
.
<cache-provider> <class>org.pentaho.platform.plugin.services.cache.HvCacheRegionFactory</class> <region>pentahoCache</region> <properties> <property name="someProperty">someValue</property> </properties> </cache-provider>
The specified class must extend org.hibernate.cache.spi.AbstractRegionFactory
and/or implement
org.hibernate.cache.spi.RegionFactory
.
Each implementation of the org.hibernate.cache.spi.RegionFactory
has 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 region factories (notably the
org.hibernate.cache.EhCacheRegionFactory
) 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 IPentahoSession
object to be passed in. The cache
manager uses the IPentahoSession.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:
-
RegionFactory
Cache
-
Field Summary
FieldsFields inherited from interface org.pentaho.platform.api.engine.ICacheManager
GLOBAL, SESSION
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addCacheRegion
(String region) boolean
addCacheRegion
(String region, Properties cacheProperties) boolean
addCacheRegion
(String region, org.hibernate.Cache cache) boolean
boolean
cacheEnabled
(String region) void
void
void
clearRegionCache
(String region) getAllEntriesFromRegionCache
(String region) getAllKeysFromRegionCache
(String region) getAllValuesFromRegionCache
(String region) long
long
getElementCountInRegionCache
(String region) long
getFromGlobalCache
(Object key) getFromRegionCache
(String region, Object key) getFromSessionCache
(org.pentaho.platform.api.engine.IPentahoSession session, String key) protected org.hibernate.cache.spi.RegionFactory
Returns the underlying regionFactory (implementsorg.hibernate.cache.RegionFactory
)void
killSessionCache
(org.pentaho.platform.api.engine.IPentahoSession session) void
void
onLogout
(org.pentaho.platform.api.engine.IPentahoSession session) void
putInGlobalCache
(Object key, Object value) void
putInRegionCache
(String region, Object key, Object value) void
putInSessionCache
(org.pentaho.platform.api.engine.IPentahoSession session, String key, Object value) void
void
removeFromRegionCache
(String region, Object key) void
removeFromSessionCache
(org.pentaho.platform.api.engine.IPentahoSession session, String key) void
removeRegionCache
(String region) protected void
setupRegionProvider
(Properties cacheProperties)
-
Field Details
-
logger
protected static final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
CacheManager
public CacheManager()The constructor performs the following tasks:- Gets the Hitachi Vantara System Settings
- Reads the
cache-provider/class
element. - Reads the
cache-provider/region
element. - Reads in any properties under
cache-provider/properties/*
- Attempts to instance the cache provider classes specified
- Starts the cache (see the
org.hibernate.cache.CacheProvider
interface) - Calls the buildCache method (see the
org.hibernate.cache.CacheProvider
interface)
-
-
Method Details
-
setupRegionProvider
-
cacheStop
public void cacheStop()- Specified by:
cacheStop
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getRegionFactory
protected org.hibernate.cache.spi.RegionFactory getRegionFactory()Returns the underlying regionFactory (implementsorg.hibernate.cache.RegionFactory
)- Returns:
- regionFactory.
-
cacheEnabled
- Specified by:
cacheEnabled
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
onLogout
public void onLogout(org.pentaho.platform.api.engine.IPentahoSession session) - Specified by:
onLogout
in interfaceorg.pentaho.platform.api.engine.ICacheManager
- Specified by:
onLogout
in interfaceorg.pentaho.platform.api.engine.ILogoutListener
-
addCacheRegion
- Specified by:
addCacheRegion
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
addCacheRegion
- Specified by:
addCacheRegion
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
addCacheRegion
-
clearRegionCache
- Specified by:
clearRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeRegionCache
- Specified by:
removeRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
putInRegionCache
- Specified by:
putInRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getFromRegionCache
- Specified by:
getFromRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getAllValuesFromRegionCache
- Specified by:
getAllValuesFromRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getAllKeysFromRegionCache
- Specified by:
getAllKeysFromRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getAllEntriesFromRegionCache
- Specified by:
getAllEntriesFromRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeFromRegionCache
- Specified by:
removeFromRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
cacheEnabled
public boolean cacheEnabled()- Specified by:
cacheEnabled
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
clearCache
public void clearCache()- Specified by:
clearCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getFromGlobalCache
- Specified by:
getFromGlobalCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getFromSessionCache
public Object getFromSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key) - Specified by:
getFromSessionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
killSessionCache
public void killSessionCache(org.pentaho.platform.api.engine.IPentahoSession session) - Specified by:
killSessionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
killSessionCaches
public void killSessionCaches()- Specified by:
killSessionCaches
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
putInGlobalCache
- Specified by:
putInGlobalCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
putInSessionCache
public void putInSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key, Object value) - Specified by:
putInSessionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeFromGlobalCache
- Specified by:
removeFromGlobalCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
removeFromSessionCache
public void removeFromSessionCache(org.pentaho.platform.api.engine.IPentahoSession session, String key) - Specified by:
removeFromSessionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getElementCountInRegionCache
- Specified by:
getElementCountInRegionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getElementCountInSessionCache
public long getElementCountInSessionCache()- Specified by:
getElementCountInSessionCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-
getElementCountInGlobalCache
public long getElementCountInGlobalCache()- Specified by:
getElementCountInGlobalCache
in interfaceorg.pentaho.platform.api.engine.ICacheManager
-