EHCache
Ehcache is an open-source Java-based caching library used to improve application performance by storing frequently accessed data in memory (and optionally on disk). It’s commonly used inside Java applications to reduce database load and speed up response times.
EHCache is Java's most widely-used cache system. Ehcache is an open source, standards-based cache for boosting performance, offloading your database, and simplifying scalability. It's the most widely-used Java-based cache because it's robust, proven, and full-featured. Ehcache scales from in-process, with one or more nodes, all the way to mixed in-process/out-of-process configurations with terabyte-sized caches.
EHCache features memory and disk stores, replicate by copy and invalidate, listeners, cache loaders, cache extensions, cache exception handlers, a gzip caching servlet filter, RESTful and SOAP APIs. Ehcache is available under an Apache open source license and is actively supported.
Ehcache is a simple, fast, thread safe, standards based cache for Java, and provides memory and disk stores and distributed operation for clusters. ehcache is widely used in such open source projects as Hibernate and Spring.
Why use Ehcache?
You use Ehcache to:
• Reduce database queries
• Improve application performance
• Cache frequently accessed data locally
• Avoid network calls to external cache systems
It’s especially useful in Java applications using frameworks like Spring or Hibernate.
When should you use Ehcache?
Ehcache is a good fit when:
• You’re building a Java application
• You want simple, in-memory caching
• You need fast local access (no network latency)
• Your app runs on a single node or small cluster
Less ideal when:
• You need distributed caching across many servers
• You require large-scale clustering
• You’re not working in Java
Key components of Ehcache
1. Cache Manager
• Central controller that manages caches
2. Cache
• Stores key-value pairs
• Can be memory-based or disk-based
3. Storage tiers
• Heap (RAM)
• Off-heap (outside JVM memory)
• Disk (persistent storage)
4. Configuration
• XML or programmatic configuration
• Defines cache size, expiration, policies
Key features of Ehcache
• In-memory caching (very fast)
• Optional disk persistence
• Expiration policies (TTL, TTI)
• Eviction strategies (LRU, LFU, FIFO)
• JCache (JSR-107) support
• Integration with Hibernate and Spring
• Multi-tier storage (heap + disk)
Advantages
• Very fast (no network calls)
• Easy to integrate into Java apps
• Reduces load on databases
• Supports persistence (unlike some caches)
• Flexible configuration
Disadvantages
• Not truly distributed (unless using enterprise extensions)
• Limited scalability compared to distributed caches
• JVM memory constraints
• Not suitable for polyglot (non-Java) environments
Common use cases
• Hibernate second-level cache
• Caching database query results
• Session data (small-scale apps)
• Frequently accessed configuration data
Alternatives
1. Caffeine
• Modern, high-performance Java cache
• Often faster than Ehcache
2. Redis
• Distributed, network-based cache
3. Hazelcast
• Distributed caching for Java
4. Memcached
• Simple distributed cache
Historical Info about EHCache
Ehcache was originally developed by Greg Luck, starting in 2003. In 2009, the project was purchased by Terracotta, who provides paid support. The software is still open source but some new major functionalities (Fast Restartability Consistency) are available only in commercial products like Enterprise EHCache and BigMemory, which are not open source. In March 2011, the Wikimedia Foundation announced it would use Ehcache to improve the performance of its wiki projects.
Terracotta actively develops, maintains, and supports Ehcache as a professional open source project available under an Apache 2 license. In addition to the open source Ehcache edition, Terracotta offers BigMemory for enterprise-grade in-memory data management with high availability, worldwide 24x7 professional support, consulting, and training services.