cache2k – High Performance Java Caching
cache2k focuses on providing a well engineered in-memory object cache implementation for Java applications.
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
- Small jar file (less than 400k) with no external dependencies
- Even smaller, for use with Android
- Fastest access times, due to non blocking and wait free access of cached values, Blog article
- Java 6 and Android compatible
- Leverages Java 8 to increase performance (if possible)
- Pure Java code, no use of sun.misc.Unsafe
- Thread safe, with a complete set of atomic operations
- Resilience and smart exception handling
- Null value support, see User Guide - Null Values
- Automatic Expiry and Refresh: duration or point in time, variable expiry per entry, delta calculations
- CacheLoader with blocking read through, see User Guide - Loading and Read Through
- CacheWriter
- Event listeners
- Refresh ahead reduces latency
- Low Overhead Statistics and JMX support
- Separate API with stable and concise interface
- complete JCache / JSR107 support, complatible to JCache Specification 1.1
- XML based configuration, to separate cache tuning from logic
Integrations
- Spring Framework
- Scala Cache
- Datanucleus (via JCache)
- Hibernate (via JCache)
- …. and probably more, please raise an issue and get it listed!
News
- Version 1.2.3.Final, 2019-08-08: Service release for stable version, See Version 1.2.3.Final release notes
- Version 1.2.2.Final, 2019-06-06: Service release for stable version, See Version 1.2.2.Final release notes
- Version 1.2.1.Final, 2019-03-08: Service release for stable version, See Version 1.2.1.Final release notes
- Version 1.2.0.Final, 2018-08-23: Release of new stable version, See Version 1.2.0.Final release notes
- Version 1.1.4.Beta, 2018-08-14: Preview. XSD Schema improvements, first release candidate for 1.2, See Version 1.1.4.Beta release notes
- Version 1.1.3.Alpha, 2018-08-02: Preview. Configuration infrastructure improvements, XSD Schema, See Version 1.1.3.Alpha release notes
- Version 1.1.2.Alpha, 2018-07-17: Preview. Spring integration, JCache cache creation, IntCache optimization, See Version 1.1.2.Alpha release notes
- Version 1.1.1.Alpha, 2018-07-02: Preview. new jar file structure, See Version 1.1.1.Alpha release notes
- Version 1.0.2.Final, 2017-12-29: Support JCache standard 1.1, See Version 1.0.2.Final release notes
- Version 1.0.1.Final, 2017-08-14: minor bugfix release, See Version 1.0.1.Final release notes
- Version 1.0.0.Final, 2017-07-11: Minor documentation tweaks, allow more chars in a cache name, See Version 1.0.0.Final release notes
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
- Andrius Velykis for his maven reflow theme
- Maximilian Richt for customizing the reflow theme and polishing the cache2k.org site design
- Dr. Song Jiang for support, Hompage of Dr. Song Jiang