Sunday, May 16, 2010

Quick overview of java caching frameworks. Pilot choice for the OpenMRS project.

Choosing a java caching framework. Searching through the Internet I found several widely-used caching frameworks. I did not consider light weight caching frameworks but only general purposes caching frameworks. Also I looked to the releases page to see how projects are maintained.
I found spring-modules project, which goal is to extend the spring framework, facilitate integration between Spring and other projects.

Requirements:
  • Memory cache
  • Disk cache
  • Expiration time for cached objects
  • Good maintained

So I decided to do quick overview of the next caching frameworks met my requirements:
  1. JBoss cache
  2. Apache JCS
  3. Ehcache
All these caches support memory cache, disk cache, remote cache etc., have a lot of different features and any of theme can be chosen.

JBoss cache is a replicated and transactional cache. It has two versions: Core and POJO. Core edition is  basis of the library. POJO edition is built atop the Core library, also extends it.
Transactional model make us not to worry about in-memory locks on updating cache.
Supports cache listeners for handling cache events. It is thread safe. Has six eviction policies (LRU - east recently used; LFU - least frequently used; MRU - most recently used; FIFO - first-in-first-out queue; ExpirationPolicy; ElementSizePolicy).

Apache JCS is a distributed caching system. As they write it is most useful for high read, low put applications. It operates with cache regions. Each region can be configured as a different cache (memory, disk, lateral, remote) with different algorithms and has own configuration.
It is not transactional. They wrote on their web site jcs is faster than ehcache but this is not the most important thing I think. Has only LRU eviction policy out of the box, but there plugging with another policies. Has own LRUMap implementation which, as they say, is faster than LRUMap and LinkedHashMap that is provided with JDK.

Ehcache is widely used caching framework. At it`s beginning it based on the jcs. It is fast, simple and has minimal dependencies. Since version 2.0 it supports transactions. It is actively developing and has a lot of features. It is inherently not thread safe to modify the value. It is safer to retrieve a value, delete the cache element and then reinsert the value. Expiration policy is only for disk cache. Memory cache supports only LRU eviction policy.

Let`s discuss what to choose.

No comments:

Post a Comment