- Home
- Caching Software
- cache2k
cache2k
Munich, Germany
What it is
cache2k is a free, open-source library for caching Java application objects in memory. It supports automatic expiry, refresh and refresh ahead, read-through loading, and event listeners. Cache loaders can handle exceptions with configurable suppression and retries. The project describes its implementation as pure Java, without external dependencies or use of sun.misc.Unsafe, and says its JAR is smaller than 400 KB. Integrations listed by the project include Spring Framework, Scala Cache, DataNucleus through JCache, and Hibernate through JCache. cache2k supports JCache / JSR 107; its guide says the implementation follows corrected TCK 1.1 semantics with one stated exception. Monitoring options include low-overhead statistics and JMX, with Micrometer metrics also documented. Version 2 requires at least Java 8 and is described as compatible with Android API level 26. The Apache-licensed library is available from Maven Central. It does not persist data, and using the JCache API adds overhead compared with cache2k’s native API.
For and against
For
- Pure Java implementation with no external dependencies.
- Supports expiry, refresh, refresh ahead, and read-through loading.
- Configurable exception suppression and retries for cache loaders.
- Offers statistics, JMX support, and Micrometer metrics.
- Apache-licensed and free.
Against
- Does not persist cached data.
- Version 2 requires at least Java 8.
- JCache API use adds overhead compared with the native API.
The verdict
cache2k provides a broad set of in-memory caching behaviors and monitoring options in a Java library. Consider its Java 8 minimum, lack of persistence, and the extra overhead of using JCache.
Who it suits
cache2k suits Java developers who need in-memory caching for application objects and want integrations such as Spring Framework or JCache. It can also suit Android projects that meet the documented API level requirement.
Plans and prices
cache2k
Apache-licensed Java library · available from Maven Central
Read 9 Oct 2026 · cache2k.org
On the record
- Android
- The guide says cache2k version 2 is compatible with Android API level 26 and that Android CI testing is implemented.cache2k.org · read 9 Oct 2026
- Cache behavior
- Features include automatic expiry, refresh, refresh ahead, read-through loading, and event listeners.cache2k.org · read 9 Oct 2026
- Implementation
- It is written in pure Java and does not use sun.misc.Unsafe.cache2k.org · read 9 Oct 2026
- Integrations
- The site lists Spring Framework, Scala Cache, DataNucleus through JCache, and Hibernate through JCache integrations.cache2k.org · read 9 Oct 2026
- License
- The project says its code is released under the Apache license.cache2k.org · read 9 Oct 2026
- Lightweight
- The project describes its JAR as smaller than 400 KB and says it has no external dependencies.cache2k.org · read 9 Oct 2026
- Limitations
- The guide says JCache API use has additional overhead compared with the native cache2k API.cache2k.org · read 9 Oct 2026
- Monitoring
- The project lists low-overhead statistics and JMX support; the guide also documents Micrometer metrics.cache2k.org · read 9 Oct 2026
- Purpose
- cache2k is an in-memory object caching library for Java applications.cache2k.org · read 9 Oct 2026
- Resilience
- Cache loaders support exception handling, including configurable exception suppression and retries.cache2k.org · read 9 Oct 2026
- Runtime requirement
- The version 2.0 release notes state that cache2k requires at least Java 8.cache2k.org · read 9 Oct 2026
- Standards
- cache2k supports JCache / JSR 107 and its guide says its implementation follows the corrected TCK 1.1 semantics, with one stated exception.cache2k.org · read 9 Oct 2026
- Support
- The project directs bug reports and feature requests to GitHub issues and general usage questions to the cache2k Stack Overflow tag.cache2k.org · read 9 Oct 2026
The review
cache2k is a Java library for keeping application objects in memory. It best suits Java teams that want a compact cache embedded in their application, with control over loading and refresh. Its strengths are breadth of cache behavior and monitoring; its scope stops at transient, in-process data.
Overview
cache2k runs within a Java application and targets Java objects, rather than operating as a separate cache service. Its JAR is smaller than 400 KB and has no external dependencies. Written in pure Java without sun.misc.Unsafe, it offers a lightweight option for teams that want to add caching without bringing in a larger runtime dependency set.
That embedded design is also its main boundary: cached data is not persisted. Applications must be able to reload or rebuild values after a restart, and cache2k is not suited to cases that require durable cache contents.
Key features
Automatic expiry, refresh and refresh ahead give teams ways to manage how long values remain useful and when they are updated. Read-through loading can fetch a value when needed, while event listeners let an application respond to cache events. These options make cache2k a flexible choice when the timing of loads and refreshes matters.
Cache loaders support exception handling, configurable suppression and retries. This gives applications some control over loader failures instead of treating every failed load the same way. The project also provides low-overhead statistics and JMX support, and its guide documents Micrometer metrics, which can help teams observe cache behavior alongside application metrics.
Integrations include Spring Framework and Scala Cache, plus DataNucleus and Hibernate through JCache. cache2k supports JCache / JSR 107, and its guide says the implementation follows corrected TCK 1.1 semantics with one stated exception. JCache can ease integration where an application already uses that standard, though using the JCache API adds overhead compared with cache2k's native API.
Pricing
cache2k is free and open source under the Apache license. The cache2k plan costs nothing and is available from Maven Central. There is no paid plan or free trial to weigh; teams take on deployment within their own application rather than paying for a hosted cache.
Platforms
The library is listed for Android, API, Linux and self-hosted use. Version 2 requires at least Java 8; its guide says it is compatible with Android API level 26 and that Android CI testing is implemented. Teams should check that runtime floor against their application before adopting it.
Who it's for
cache2k is a good fit for Java developers who want an embedded object cache with flexible expiry, loading and refresh behavior, and who value monitoring hooks or existing integrations. It is less suitable when the cache must persist data, when a separate shared cache service is required, or when a project cannot use Java 8 or newer for version 2.
Pros and cons
- Compact, dependency-free library: a JAR smaller than 400 KB with no external dependencies keeps the addition relatively lean.
- Broad cache controls: expiry, refresh, read-through loading, listeners, retries and exception suppression cover several common application caching needs.
- Monitoring and integration options: statistics, JMX, Micrometer documentation and framework integrations can fit into existing Java applications.
- No persistence: values do not survive restarts, so the library cannot serve as durable storage.
- JCache has extra overhead: applications that use the standard API trade some efficiency against the native cache2k API.
- Java runtime floor: version 2 requires Java 8 or newer, which rules it out for older runtimes.
Alternatives
Caffeine is another free, self-hosted Java caching library; its 3.x line requires Java 11 or newer, while Java versions below 11 use 2.x. Google Guava Cache is a free alternative for Android, Linux and Windows. Ehcache is a free, Apache 2.0 open-source option for API and self-hosted use.
Aiven for Valkey offers a hosted route, with a free plan billed at $0/month for one dedicated VM, one CPU and 1 GB RAM; that plan has no specific cloud or region and excludes integrations and connection pooling. Amazon ElastiCache is a paid service with a free tier. Memcached is free, open-source, self-hosted software for teams considering another cache engine. Garnet is another alternative. Accessibility Test Framework for Android is also listed as a free option.
Verdict
Choose cache2k for a Java application that needs a compact, configurable in-memory cache with loading, refresh and monitoring features, and can treat cached values as temporary. Its Apache-licensed, dependency-free library is the strongest reason to adopt it. Look elsewhere if data must persist or if the application needs a cache service beyond its own process.