Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This document describes how to use ICacheManager in your plugin or extension of the BI Platform. The default implementation of the ICacheManager interface supports cache regions (segmentation of keys along a particular use-case). The standard regions are GLOBAL (putInGlobalCache / getFromGlobalCache), and SESSION (putInSessionCache / getFromSessionCache). Plugins are permitted to use these regions as they are, or they can define their own cache region (addCacheRegion). When a plugin defines a cache region, the plugin is responsible for the life-cycle of that cache region. That is, the startup and shutdown of that region is the responsibility of the plugin and should be managed from a lifecycle listener.

A plugin would need to define its own cache region if the plugin needed a separate cache area that needs to be flushed independently from the GLOBAL or SESSION caches. Be careful though to never put user-session specific data outside the SESSION cache. The SESSION cache has special session-expiration code that clears the SESSION cache when a user logs out (or the HTTPSession times out).

Since the present ICacheManager doesn't yet support session-segmented independent regions, there are two choices for implementing this capability:

  • As shown in http://jira.pentaho.com/browse/CDF-53, you could incorporate a combination ILogoutListener with your LifecycleListener. This would let you have a doubly-segmented cache that would require a small bit of extra management.
  • You could use creative key-specification and use the existing SESSION cache. In this way, when the session expires, all settings will naturally be removed from the cache. This gets ugly when multiple session-caches need flushed at the same time though.

Before using PentahoSystem's ICacheManager, you must configure ehcache to contain the cache regions. Otherwise, they will default to the defaultCache.

...

Code Block
ICacheManager cacheMgr = PentahoSystem.getCacheManager(pentahoSession);

Creating a cache:
* Note - this should be done in the startup of your lifecycle listener.

Code Block
if(!cacheMgr.cacheEnabled("your_plugin_cache")) {
      cacheMgr.addCacheRegion("your_plugin_cache");
}

Removing a cache:

Code Block

\* Note - this should be done in the shutdown of your lifecycle listener.
if ( (cacheMgr != null) && (cacheMgr.cacheEnabled("your_plugin_cache")) ) {
  cacheMgr.removeRegionCache("your_plugin_cache");
}

Clearing the cache:

...