Tuesday, March 07, 2006

Java Object Caching with EHCACHE

EHCache is a pure Java, in-process cache available on Source-Forge. It is the default pluggable cache for Hibernate 3.0. In light of the fact that support for Java Caching System is being removed from Hibernate, EHCache gains some extra notice. EHCache supports Less Frequently Used (LFU), First-In-First-Out (FIFO) algorithms in addition to Least Recently Used (LRU) algorithm for cache eviction. The following types of cache stores are supported in EHCache:
  • Memory cache
  • Disk Cache
  • Distributed cache
The following description of the features in EHCache that meet our requirements
  • Dependencies: For JDK1.4, JDK1.5 and JDK 1.6, EHCache requires commons-logging and commons-collections 2.1.1 from Apache's Jakarta project.
  • Element grouping: Element grouping is not supported in EHCache. The only level of grouping allowed in EHCache is at the cache level. A single cache manager can manage multiple caches.
  • Data Expiration: Data expiration can be set declaratively as well as programmatically at the cache level. EHCache does not provide support for setting expiration values at the element level.
  • Configurable runtime properties: Runtime parameters can be configured in the xml file, which can be defined externally. The XML file has to conform to the schema defined in the ehcache.xsd. The properties that can be configured at the region level include maximum objects, cache name, size, shrink interval etc.
  • Element event handling: EHCache allows to attach event handlers to the cache manager (cache add, remove) and the cache (put, update, remove).
I did not provide any code samples here because the invocation is quite straight forward and the configuration values are similar to that of Java Caching System except that they will be defined in XML instead of property file. All the documentation for EHCACHE is found in one place.

No comments:

Post a Comment

Popular Posts