Why Caffeine?
Caffeine offers exceptional performance through advanced eviction algorithms and concurrent design:- High performance: Superior throughput and hit rates compared to traditional caching solutions
- Near optimal eviction: Uses the W-TinyLFU algorithm for frequency and recency-based eviction
- Flexible configuration: Mix and match features to build exactly the cache you need
- Production ready: Powers infrastructure at Cassandra, Kafka, HBase, Apache Solr, and many more
Get started
Installation
Add Caffeine to your Java project with Maven, Gradle, or manual download
Quickstart
Build your first cache in minutes with step-by-step examples
Core concepts
Learn about cache types, eviction policies, and configuration options
API reference
Explore the complete API documentation and advanced features
Features at a glance
Caffeine provides flexible construction to create a cache with any combination of these optional features:Population strategies
- Manual loading: Explicitly add entries with
put()and retrieve withgetIfPresent() - Automatic loading: Cache automatically loads missing entries using a
CacheLoader - Async loading: Load entries asynchronously with
AsyncCacheandAsyncLoadingCache
Eviction policies
- Size-based eviction: Limit cache size by entry count or total weight
- Time-based expiration: Expire entries after access or write
- Custom expiration: Define per-entry expiration with the
Expiryinterface - Reference-based eviction: Use weak or soft references for keys and values
Performance features
- Refresh: Asynchronously refresh stale entries to keep cache warm
- Statistics: Track hit rate, miss rate, eviction count, and load times
- Write-through: Propagate writes to an external data source
- Removal listeners: Get notified when entries are evicted or removed
Extensions
- JSR-107 JCache: Standard Java caching API compatibility
- Guava adapters: Drop-in replacement for Guava’s cache
- Simulator: Test and tune cache configurations
Key characteristics
Caffeine is implemented as a concurrent hash table with performance characteristics similar to
ConcurrentHashMap. It uses weakly consistent iterators that are safe for concurrent use and never throw ConcurrentModificationException.equals() for key and value comparisons. When weak references are enabled, identity (==) comparisons are used instead.
Real-world usage
Caffeine powers critical infrastructure across the industry:- Distributed systems: Cassandra, Kafka, HBase, Accumulo
- Search and analytics: Apache Solr, Druid, Neo4j
- Data grids: Coherence, Infinispan, Redisson
- Web frameworks: Spring Cache, Play Framework, Micronaut, Quarkus
- Cloud platforms: OpenWhisk serverless platform
Next steps
Ready to add high-performance caching to your application?Install Caffeine
Get started with Maven, Gradle, or direct JAR download
Quick start guide
Build a working cache in under 5 minutes