[Introduction to Ehcache of Distributed Cache]

Ehcache is a widely used open source Java distributed cache. Mainly for general purpose caches, Java EE and lightweight containers. It features in-memory and disk storage, cache loaders, cache extensions, cache exception handlers, a gzip cache servlet filter, support for REST and SOAP api, etc.

Ehcache is an open source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. It's the most widely-used Java-based cache because it's robust, proven, full-featured, and integrates with other popular libraries and frameworks. Ehcache scales from in-process caching, all the way to mixed in-process/out-of-process deployments with terabyte-sized caches.



 

 

The main features are:

1. Fast

2. Simple

3. Multiple caching strategies

4. There are two levels of cache data: memory and disk, so there is no need to worry about capacity issues

5. Cached data will be written to disk during virtual machine restart

6. Distributed caching through RMI, pluggable API, etc.

7. Listening interface with cache and cache manager

8. Supports multiple cache manager instances, and multiple cache areas for one instance

9. Provide Hibernate's cache implementation



 

 

The class hierarchy model of Ehcache mainly consists of three layers. The top layer is CacheManager, which is the entry for operating Ehcache. We can get a single CacheManager through CacheManager.getInstance(), or create a new CacheManager through CacheManager's constructor. Each CacheManager manages multiple Caches. And each Cache is associated with multiple Elemenats in a Hash-like way. Element is where we store the content we want to cache.



 

ehcache refresh strategy

The refresh strategy of ehcache is to record a put time when the cache is put in. It uses the method of Lazy Evict and compares it with the set TTL when taking it.

3 clearing strategies for ehcache cache:

1 FIFO, first in first out

2 LFU, the least used, the cached element has a hit attribute, and the one with the smallest hit value will be cleared from the cache.

3 LRU, the least recently used, the cached element has a timestamp. When the cache capacity is full and space needs to be made to cache new elements, then the timestamp of the existing cache elements is farthest from the current time. The element will be flushed out of the cache.

 

Original is not easy, welcome to reward, please look for the correct address, beware of counterfeiting



 

 


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326611907&siteId=291194637