explaingit

ben-manes/caffeine

Analysis updated 2026-06-24

17,649JavaAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

Caffeine is a Java in-memory caching library with size and time-based eviction, async refresh, and removal notifications. Used by Spring, Kafka, Cassandra.

Mindmap

mindmap
  root((caffeine))
    Inputs
      Cache keys
      Loader functions
      Size and time limits
    Outputs
      Cached values
      Eviction notifications
      Hit and miss stats
    Use Cases
      Speed up DB queries
      Cache API responses
      Memoize computations
      Replace Guava cache
    Tech Stack
      Java
      Maven Central
      Gradle
      JSR-107 JCache
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Cache expensive database query results in a Spring Boot service.

USE CASE 2

Add a size-bounded in-memory cache to a Java REST API.

USE CASE 3

Replace Google Guava's cache with a near-optimal eviction policy.

USE CASE 4

Wrap a slow third-party API call with time-based expiration.

What is it built with?

JavaMavenGradleJCache

How does it compare?

ben-manes/caffeinetencent/tinkerinfinilabs/analysis-ik
Stars17,64917,63117,448
LanguageJavaJavaJava
Setup difficultyeasyhardmoderate
Complexity2/54/53/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 30min

Java 11+ required for the 3.x line, older JVMs must stay on 2.x.

Apache 2.0 lets you use, modify, and ship this in commercial products freely as long as you keep the license notice.

In plain English

Caffeine is a Java library that provides high-performance in-memory caching. Caching means storing the results of expensive operations, like database queries or complex calculations, in fast memory so that future requests for the same data can be served immediately instead of recomputing from scratch. Caffeine is designed to be both fast and smart about which items to keep and which to discard when the cache fills up. The library lets you configure a cache with several useful behaviors: you can set a maximum number of items it holds, have entries automatically expire after a set time since they were last written or accessed, have stale entries refreshed in the background without blocking your application, and get notified when an item is removed. Caffeine uses an eviction strategy (deciding what to throw away when full) based on how frequently and how recently items have been used, which research papers show is close to theoretically optimal for real-world workloads. It is built in Java and available through Maven Central (a standard package registry for Java projects). Integration with many popular Java frameworks is available, including Spring, Quarkus, and Micronaut, and it is also used by large infrastructure projects like Kafka, Cassandra, and Apache Solr. You would use Caffeine when you have a Java application that repeatedly fetches or computes the same expensive results and you want to speed it up by keeping those results in memory, with fine-grained control over how long to keep them and what to do when memory runs low.

Copy-paste prompts

Prompt 1
Show me a minimal Caffeine LoadingCache example in Java with a max size of 1000 and 10-minute expireAfterWrite.
Prompt 2
Wire Caffeine into my Spring Boot app as the @Cacheable backend with size and TTL configured via application.yml.
Prompt 3
Convert this Guava CacheBuilder code to Caffeine and explain any behavior differences.
Prompt 4
Add Caffeine to a Gradle project and set up an async LoadingCache that refreshes stale entries in the background.
Prompt 5
Configure a Caffeine cache that fires a removal listener whenever an entry is evicted so I can log it.

Frequently asked questions

What is caffeine?

Caffeine is a Java in-memory caching library with size and time-based eviction, async refresh, and removal notifications. Used by Spring, Kafka, Cassandra.

What language is caffeine written in?

Mainly Java. The stack also includes Java, Maven, Gradle.

What license does caffeine use?

Apache 2.0 lets you use, modify, and ship this in commercial products freely as long as you keep the license notice.

How hard is caffeine to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is caffeine for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub ben-manes on gitmyhub

Verify against the repo before relying on details.