Why & How

WHY ?

This is a powerful yet simple LRUCachingMap implementation.
Short defintion: Caches key/values for a certain amount of time, when ever a key is "get" the expiration time can be extended.

It is all POJO classes, so no external setup of configuration files, facets, metadata properties etc.

It makes heavy use of generics and is therefore highly extendable.

It supports persistences of your cache.

And it can comes with the 1 default implementation and 6 versitale versions of that
  • Caching in memory.
  • Caching file references.
  • Caching as xml files - with 3 variations.
  • Caching as serialized files - with 3 variations.
  • Caching in a JPA table.
  • Caching in a grouped JPA table. Where many caching instances share the same table.

HOW ?

First choose the type of your Key and Value.

Than choose if your want cache the value in memory or it has to be persisted.

There is a LRUCachingMapFactory which is extremely useful, but as you will see in the library it is very easy to customize.

To get you going - if you write this.
DefaultLRUCachingMap<Long,String> cache =LRUCachingMapFactory.createMemoryCache(DefaultLRUCachingMapConfiguration.ONE_DAY());
You will have a "memory" cache where:
  • The key is of type "Long".
  • The value is of type "String".
  • The keys is stored for one day (24 hours).
  • Everytime a "key" is "get" the expiration datetime for the key is extended by 1 hour.
  • A key can maximum be extended 5 times.
  • There can maximum be 10000 keys in the cache.
  • A cleanup thread runs every 15 minutes.