cache2k focuses on providing a well engineered in-memory object cache implementation for Java applications.

GitHub Stars License Stack Overflow Maven Central

  Cache<String,String> cache = new Cache2kBuilder<String, String>() {}
    .expireAfterWrite(5, TimeUnit.MINUTES)    // expire/refresh after 5 minutes
    .resilienceDuration(30, TimeUnit.SECONDS) // cope with at most 30 seconds
                                              // outage before propagating 
                                              // exceptions
    .refreshAhead(true)                       // keep fresh when expiring
    .loader(this::expensiveOperation)         // auto populating function

For a detailed introduction continue with Getting Started.

Features at a glance


Integrating cache2k in your project

chacke2k is on maven central. Maven users add the following dependencies:


Please replace ${cache2k-version} with the latest version.


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


The code is released under Apache license.


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
  • Caffeine

Distributed caches:

  • Infinispan
  • hazelcast
  • redsisson
  • Apache ignite


Back to top

Version: 1.0.2.Final. Last Published: 2017-12-29.