cache2k focuses on providing a well engineered in-memory object cache implementation for Java applications. The implementation leads back to a project started in 2000, hence the name cache2k.


  • Version 0.22.1, 2016-01-13: Bugfix release, Update recommended. See Version 0.22.1 release notes
  • Version 0.22, 2015-12-29: Minor bug fix release. See Version 0.22 release notes
  • Version 0.21.1, 2015-06-13: Fix Android compatibility. Closes GH#19
  • Version 0.21, 2015-02-04: Rewrite internal entry locking. Bunch of new methods and interfaces. See Version 0.21 release notes
  • 2015-02-01: FOSDEM talk, mostly covering advanced eviction techniques and latest benchmarks with Version 0.21, see slides on slideshare
  • Version 0.20, 2014-11-11: Revised configuration, iterator, improved exception handling, android compatible core module, see Version 0.20 release notes
  • Version 0.19.2, 2014-09-23: Rerelease of 0.19, compatible to Android. JMX support is dropped in this version. JMX support will be available in an extra jar in the future.
  • Version 0.19.1, 2014-03-13: Rerelease, now on Maven Central!
  • Version 0.19, 2014-02-25: JMX support enabled, bulk API enhancements, simple transaction support, see Version 0.19 release notes
  • Version 0.18, 2013-12-18: Initial open source release


We use every cache2k release within production environments. However, some of the basic features are still evolving and there may be API breaking changes until we reach version 1.0.

Integrating cache2k in your project

chacke2k is on maven central. If you use maven, add to your project pom:


Please replace ${cache2k-version} with the latest version. The cache2k-core module is compatible with Java 6 environments including android.

For Java enterprise applications, add this to your dependencies:


This will add JMX support.

Getting started

Here are two quick examples how to construct a cache and destroy it again.

cache-aside / direct cache manipulation

For direct cache manipulation you can use the methods peek() and put():

Cache<String,String> c =
  CacheBuilder.newCache(String.class, String.class).build();
String val = c.peek("something");
c.put("something", "hello");
val = c.get("something");

read-through caching

Instead of direct manipulation it is possible to register a cache source. If no data is available within the cache, the cache will delegate to the cache source:

CacheSource<String,Integer> _lengthCountingSource =
  new CacheSource<String, Integer>() {
    public Integer get(String o) throws Throwable {
      return o.length();
Cache<String,Integer> c =
  CacheBuilder.newCache(String.class, Integer.class)
int v = c.get("hallo");
assertEquals(5, v);
v = c.get("long string");
assertEquals(11, v);

Mind, that the methods get() and peek() have distinct behaviour in cache2k. get() will always do its best to get the date, peek() will only return data if the cache contains it. The presence of the cache source does not change this behaviour.


The main aim is to get a small footprint core cache implementation which does

  • Fast
  • Even faster with lock free cache access (experimental), see the benchmarks page
  • Exception support
  • Null value support
  • Expiry/update on time
  • Background refreshing
  • Nice statistics
  • JMX

Since it is fresh open source, we will put up a detailed description of each feature as well polish the API and semantics one after another. See our todo list


Please use the issue tracker for bugs and wishes you step upon. We also monitor the tag cache2k for general usage questions.


The code is released under GPLv3. We are aware, that this is not a fit for everyone. Details are discussed at Issue 13.


cache2k does not try to be a full blown distributed enterprise caching solution. Some alternatives which you should take a look on:

  • Google Guava Cache
  • EHCache
  • JCS
  • JBoss Infinispan


Back to top

Version: 0.22.1. Last Published: 2016-01-13.