org.kuali.student.common.util
Class EhCacheHelper

java.lang.Object
  extended by org.kuali.student.common.util.EhCacheHelper

public class EhCacheHelper
extends Object

Simplified api for enabling Service and DAO classes with EhCache.

Author:
garystruthers

Field Summary
private  net.sf.ehcache.CacheManager cacheManager
           
 
Constructor Summary
EhCacheHelper()
           
EhCacheHelper(String configurationFileName)
           
 
Method Summary
 void createCache(String cacheName)
          Creates a cache and adds it to the cache manager
 void evictAllCacheElements(String cacheName)
          Remove all elements from cache
 void evictCacheElement(String cacheName, String key)
          Removes 1 element from cache
 net.sf.ehcache.Element getCacheElement(String cacheName, String key)
          Gets Element, useful for calling Element methods like getHitCount()
 long getCacheElementHitCount(net.sf.ehcache.Element element)
          Gets how many times element has been accessed.
 Serializable getCacheElementValue(String cacheName, String key)
          Get the thing cached
 String[] getCacheNames()
           
private  void initCacheManager()
          EhCache has a default configuration file within ehcache.jar which is used if there is no ehcache.xml in the classpath.
private  void initCacheManager(String configurationFileName)
           
 void saveOrUpdateCacheElement(String cacheName, String key, Object value)
          Like Hibernate's saveOrUpdate, this is used to create a new cache element and update existing element The cache knows if cache.put if creating or updating an element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheManager

private net.sf.ehcache.CacheManager cacheManager
Constructor Detail

EhCacheHelper

public EhCacheHelper()

EhCacheHelper

public EhCacheHelper(String configurationFileName)
Method Detail

initCacheManager

private void initCacheManager(String configurationFileName)

initCacheManager

private void initCacheManager()
EhCache has a default configuration file within ehcache.jar which is used if there is no ehcache.xml in the classpath. It is a singleton, so it's only created once.

See Also:
for default configuration, To customize configuration, add an ehcache.xml file to the classpath.

createCache

public void createCache(String cacheName)
Creates a cache and adds it to the cache manager

Parameters:
cacheName - you could name the cache with the classname that uses it.

saveOrUpdateCacheElement

public void saveOrUpdateCacheElement(String cacheName,
                                     String key,
                                     Object value)
Like Hibernate's saveOrUpdate, this is used to create a new cache element and update existing element The cache knows if cache.put if creating or updating an element.

Parameters:
cacheName -
key - must be unique, should be descriptive
value - the thing cached

getCacheElementValue

public Serializable getCacheElementValue(String cacheName,
                                         String key)
Get the thing cached

Parameters:
cacheName -
key -
Returns:
a Serializable object Note, EhCache can support non-serializable object in memory only cache

getCacheElement

public net.sf.ehcache.Element getCacheElement(String cacheName,
                                              String key)
Gets Element, useful for calling Element methods like getHitCount()

Parameters:
cacheName -
key -
Returns:

evictCacheElement

public void evictCacheElement(String cacheName,
                              String key)
Removes 1 element from cache

Parameters:
cacheName -
key -

evictAllCacheElements

public void evictAllCacheElements(String cacheName)
Remove all elements from cache

Parameters:
cacheName -

getCacheElementHitCount

public long getCacheElementHitCount(net.sf.ehcache.Element element)
Gets how many times element has been accessed. Useful for testing and optimization

Parameters:
element -
Returns:

getCacheNames

public String[] getCacheNames()
Returns:


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.