The Java Jangles Caching Wrapper

New on Java Jangles is JangleCache, a simple wrapper to Apache Commons Java Caching System (JCS.) Java Jangles is available on GitHub.

JangleCache makes it easy to cache objects through simple calls like

JangleCache.GetInstance().Put(“JangleConfiguration”);

This was the first use of JangleCache, in fact, as we’re putting the config.properties file contents into a JangleConfiguration class and then caching it. The expense of performing a disk read each time we wanted an application property was unacceptable.

JangleCache has the following public methods:

  • public static JangleCache GetInstance();
  • public Object Get(Serializable key)
  • public void Put(Serializable key, Serializable _object, double maxLifeMinutes);
  • public void Put(Serializable key, Serializable _object);
  • public void Remove(Serializable key);
  • public void Clear();

There are JCS wrappers out there that are much more extensive and complex, but I always go for the simple approach when possible.

Because JangleCache is instantiated with a static method, using it is always performed with a single line of code. The Cache Put() method was shown above. Here is how we would retrieve an object from the cache.

JangleCache.GetInstance().Get(“JangleConfiguration”);

Since there’s little more to say about JangleCache we might as well clear it from memory.

JangleCache.GetInstance().Clear();