Dragonfly Cloud is now available in the AWS Marketplace - learn more

Question: Is Ehcache a Distributed Cache System?

Answer

Yes, Ehcache is a distributed caching system. It's an open source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. Ehcache is robust, proven, full-featured, and integrates with other popular libraries and frameworks.

In its distributed configuration, Ehcache uses Terracotta server array to provide cache coherence (consistency) across multiple nodes in a cluster. This allows the application to see a single, coherent view of the cache data, which is extremely valuable in multi-node environments.

Here's an example of how you might configure Ehcache for distributed caching:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" monitoring="autodetect" dynamicConfig="true"> <cacheManagerPeerProviderFactory class="net.sf.ehcache.distribution.terracotta.TerracottaClientBootstrapCacheManagerPeerProviderFactory" properties="terracottaConfigUrl=localhost:9510"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"> <terracotta/> </defaultCache> <cache name="sampleCache1" maxEntriesLocalHeap="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="false"> <terracotta/> </cache> </ehcache>

This configuration sets up a distributed cache named 'sampleCache1', using a Terracotta server at 'localhost' on port '9510'.

Remember to add proper dependencies in your project.

Please note: the use of distributed Ehcache requires Terracotta servers. Always refer to the latest documentation for any updates or changes.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost