This document describes how to use ICacheManager in your plugin or extension of the BI Platform.
Before using PentahoSystem's ICacheManager, you must configure ehcache to contain the cache regions. Otherwise, they will default to the defaultCache.
The ehcache.xml file, which ends up located in pentaho/WEB-INF/classes/ehcache.xml, is in SVN at:
http://source.pentaho.org/svnroot/bi-platform-v2/trunk/bi-platform-engine-services/res/ehcache/ehcache.xml
Accessing the ICacheManager:
ICacheManager cacheMgr = PentahoSystem.getCacheManager(pentahoSession);
Creating a cache:
if(!cacheMgr.cacheEnabled("your_plugin_cache")) { cacheMgr.addCacheRegion("your_plugin_cache"); }
Clearing the cache:
if(cacheMgr.cacheEnabled("your_plugin_cache")) { cacheMgr.clearRegionCache("your_plugin_cache"); }
Putting items in the cache:
* Note: All objects in the cache must implement and be serializable. Otherwise errors will occur when ehcache attempts to store cached items to disk.
Object myObject = getMyObject(); cacheMgr.putInRegionCache("your_plugin_cache", "cache_item_1", myObject);
Getting items from the cache:
Object myObject = cacheMgr.getFromRegionCache("your_plugin_cache", "cache_item_1");
Getting all items from the cache:
List<MyClass> catalogs = (List<MyClass>)cacheMgr.getAllValuesFromRegionCache("your_plugin_cache");
Here is a link to the ICacheManager source:
http://source.pentaho.org/svnroot/bi-platform-v2/trunk/bi-platform-api/src/org/pentaho/platform/api/engine/ICacheManager.java