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.
Generated 2026-05-21 · Model: sonnet-4-6 · Verify against the repo before relying on details.