cache2k is an in-memory high performance Java Caching library.
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.
- 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
- XML based configuration, to separate cache tuning from logic
- Spring Framework
- Scala Cache
- Datanucleus (via JCache)
- Hibernate (via JCache)
- .... and probably more, please raise an issue and get it listed!
For more documentation and latest news, see the cache2k homepage.