On this page
Overview
Caffeine is a high-performance in-memory caching library for Java. Its Guava-inspired builder API combines size-based eviction, time-based expiration, refresh, asynchronous loading, statistics, and other policies for reusable data inside an application process.
Features and best fit
Based on official documentation; not hands-on tested · Content checked:
Key features
Evict entries with size and time policies
Maximum-size limits and access- or write-based expiration control memory usage and data freshness automatically.
Sources: [1]
Handle cache misses and refresh through loading and asynchronous APIs
Loading caches and asynchronous loading can compute values on misses, while refresh-after-write can move stale-entry refresh work away from the requesting path.
Sources: [1]
Add reference policies, removal listeners, and statistics as needed
Weak or soft references, removal notifications, and access statistics can be composed according to lifecycle and observability needs.
Sources: [1]
Best fit
Fits reuse of expensive computation or I/O results within one JVM
Database or API lookups, metadata, and computed results that are repeatedly requested can be reused at low latency inside the application process.
Sources: [1]
Before adoption
Treat it as local process state rather than a distributed cache
Caffeine is an in-memory library and does not automatically share entries across application instances. Strict cluster-wide consistency requires an external cache or explicit source-of-truth synchronization.
Sources: [1]
Tune eviction, expiration, and refresh against representative workloads
Oversized caches pressure the heap, undersized caches increase misses, and refresh can move significant work into the background. Evaluate acceptable staleness, refresh cost, and hot-key behavior under production-like traffic.
Official sources
- [1]Caffeine v3.3.0 README(2026-10-03)
- [2]Caffeine v3.3.0 release(2026-10-03)
- [3]Caffeine Apache-2.0 license(2026-10-03)
Supplemental curator note
Caffeine fits Java applications that reuse database/API results or expensive computations within one process. Even a fast cache is not the source of truth, so expiration, maximum size, acceptable staleness, and cache-miss load should be designed against real traffic.
Try it in 3 steps
- 1
Fetch Caffeine 3.3.0 into the Maven cache
Using Java 11 or later and Maven, generate a local runtime classpath for Caffeine 3.3.0 and its published API dependencies.
mkdir caffeine-demo && cd caffeine-demo && printf '%s\n' '<project xmlns="http://maven.apache.org/POM/4.0.0"><modelVersion>4.0.0</modelVersion><groupId>demo</groupId><artifactId>caffeine-demo</artifactId><version>1.0</version><dependencies><dependency><groupId>com.github.ben-manes.caffeine</groupId><artifactId>caffeine</artifactId><version>3.3.0</version></dependency></dependencies></project>' > pom.xml && mvn -q dependency:build-classpath -Dmdep.outputFile=classpath.txt - 2
Create a minimal JShell cache script
Create a small script that puts and gets one value from a process-local cache with a maximum size.
printf '%s\n' 'import com.github.benmanes.caffeine.cache.*;' 'var cache = Caffeine.newBuilder().maximumSize(10).build();' 'cache.put("key", "value");' 'System.out.println(cache.getIfPresent("key"));' '/exit' > caffeine.jsh - 3
Run the cache example in JShell
Run inside the caffeine-demo directory. If it prints value, local cache creation, storage, and retrieval are working.
jshell --class-path "$(cat classpath.txt)" caffeine.jsh
Growth
Growth trends · Last 30 days
17,882 Stars
Trend data is still being collected.
Development activity
Last 90 days · weekly
- Commits (last 30 days)
- 53
- Open PRs
- 0
Development activity is still being collected.
Built with
Categories and tags
Categories
GitHub data
GitHub dataView detailed GitHub data
- Stars
- 17,882
- Forks
- 1,721
- Watchers
- 359
- Open issues
- 1
- Contributors
- 69
- Owner type
- User
- Primary language
- Java
- License
- Apache-2.0
- Repository last updated
- Sep 30, 2026
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- OpenPDF4,373 Stars
1 shared tag(s) · 1 shared category(s) · Same language
embed PDF creation, conversion, and protection in JVM applications
Java - Apache Commons Lang3,013 Stars
1 shared tag(s) · 1 shared category(s) · Same language
fill gaps in Java core APIs with reusable utilities for strings, arrays, numbers, objects, and reflection
Java - Memcached14,287 Stars
2 shared tag(s)
Keep recomputable hot data in memory to reduce database and API read load
C - DBeaver51,949 Stars
1 shared tag(s) · 1 shared category(s) · Same language
operate many database systems from one desktop SQL workspace
Java - Netty35,065 Stars
1 shared tag(s) · 1 shared category(s) · Same language
Build high-connection protocol servers and clients in Java from event loops and channel pipelines
Java - OpenAPI Generator26,772 Stars
1 shared tag(s) · 1 shared category(s) · Same language
Generate client SDKs, server stubs, documentation, and configuration for many languages from one OpenAPI contract
Java
Report incorrect information
Tell us if any listing information is incorrect or outdated.