Fork me on GitHub

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
    .setupWith(UniversalResiliencePolicy::enable, b -> b // enable resilience policy
      .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


  • Spring Framework
  • Scala Cache
  • Datanucleus (via JCache)
  • Hibernate (via JCache)
  • …. and probably more, please raise an issue and get it listed!


Feedback and Contribute

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

See also the Contributor Guide.


The code is released under Apache license.