ben-manes /caffeine

A high performance caching library for Java

★ 17,939⑂ 1,721
JavaCreated 2014-12-13
17,939
stars
+6+7+57
1,721
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions

README

Caffeine is a [high performance][benchmarks], [near optimal][efficiency] caching library. For more
details, see our [user's guide][users-guide] and browse the [API docs][javadoc] for the latest
release.

 Cache

Caffeine provides an in-memory cache using a Google Guava inspired API. The improvements draw on our
experience designing [Guava's cache][guava-cache] and [ConcurrentLinkedHashMap][clhm].

java
LoadingCache graphs = Caffeine.newBuilder()
    .maximumSize(10_000)
    .expireAfterWrite(Duration.ofMinutes(5))
    .refreshAfterWrite(Duration.ofMinutes(1))
    .build(key - createExpensiveGraph(key));


 Features at a Glance

Caffeine provides flexible construction to create a cache with a combination of the following
optional features:

 [automatic loading of entries][population] into the cache, optionally asynchronously
 [size-based eviction][size] when a maximum is exceeded based on [frequency and recency][efficiency]
 [time-based expiration][time] of entries, measured since last access or last write
 [asynchronously refresh][refresh] when the first stale request for an entry occurs
 keys automatically wrapped in [weak references][reference]
 values automatically wrapped in [weak or soft references][reference]
 [notification][listener] of evicted (or otherwise removed) entries
 [writes propagated][compute] to an external resource
 accumulation of cache access [statistics][statistics]

In addition, Caffeine offers the following extensions:

 [JSR-107 JCache][jsr107]
 [Guava adapters][guava-adapter]
 [Simulation][simulator]

Use Caffeine in a community provided integration:

 [Spring Cache][spring]: Simple, modern, productive Java
 [Play Framework][play]: High velocity web framework
 [Micronaut][micronaut]: A modern, full-stack framework
 [Coroutines][caffeine-coroutines]: Kotlin Coroutines extension
 [Bootique][bootique]: A fast, simple Java platform
 [Quarkus][quarkus]: Supersonic Subatomic Java
 [Camel][camel]: Routing and mediation engine
 [Scaffeine][scaffeine]: Scala wrapper for Caffeine
 [JHipster][jhipster]: Generate, develop, deploy
 [Aedile][aedile]: Kotlin wrapper for Caffeine

Powering infrastructure near you:

 [Dropwizard][dropwizard]: Ops-friendly, high-performance, RESTful APIs
 [Cassandra][cassandra]: Manage massive amounts of data, fast
 [Coherence][coherence]: Mission critical in-memory data grid
 [Accumulo][accumulo]: A sorted, distributed key/value store
 [Kafka][kafka]: A distributed event streaming platform
 [HBase][hbase]: A distributed, scalable, big data store
 [Apache Solr][solr]: Blazingly fast enterprise search
 [Infinispan][infinispan]: Distributed in-memory data grid
 [Redisson][redisson]: Ultra-fast in-memory data grid
 [OpenWhisk][open-whisk]: Serverless cloud platform
 [Corfu][corfu]: A cluster consistency platform
 [Grails][grails]: Groovy-based web framework
 [Finagle][finagle]: Extensible RPC system
 [Neo4j][neo4j]: Graphs for Everyone
 [Druid][druid]: Real-time analytics

 In the News

 An in-depth descrip

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON