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
    .build();

For a detailed introduction continue with Getting Started.

Features at a glance

News

Integrating cache2k in your project

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

  <dependency>
    <groupId>org.cache2k</groupId>
    <artifactId>cache2k-api</artifactId>
    <version>${cache2k-version}</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>org.cache2k</groupId>
    <artifactId>cache2k-all</artifactId>
    <version>${cache2k-version}</version>
    <scope>runtime</scope>
  </dependency>

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

Feedback

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

License

The code is released under Apache license.

Alternatives

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

Credits

Back to top

Version: 1.0.0.Final. Last Published: 2017-07-11.