1.Overview
Ehcache from the Hibernate development, and gradually covers the entire function of the CAHCE, is currently the best development momentum of a project.
Standard cache
Distributed caching (based on RMI/JGROUPS/JMS)
URL, page fragment cache (similar to oscache related parts)
Central cache server (similar to memcached)
2. Basic function and Configuration
The basic functions of ehcache can be learned from the configuration file.
Overall, the biggest difference between caching and HashMap, is that the buffer memory is limited, the timeliness of the cache is limited, so you can set the size of the memory, you can perform the failure algorithm, can be full of memory, according to the least access algorithm to remove the cache directly or switch to the hard disk.
Also note that the Ehcache CacheManager itself has a certain default value. In the absence of a specified ehcache.xml, the Ehcache.jar will be used in the Ehcache_failsafe.xml,
The maximum number of 2.1 objects in memory
Because memory is limited, you must set the maximum number of objects per class in memory with Maxelementsinmemory (required). The Ehcache_failsafe.xml is 10000.
2.2 Expiration/emigration algorithm at maximum time in memory
Expiration algorithm: If the cache has been invalidated, humanity destroys it. The failure algorithm consists of 3 parameters:
Eternal (Required): If true, never expires, ignoring the settings for the latter two parameters. Ehcache_failsafe.xml is false.
Timetoidleseconds: Idle No access time, defaults to 0, never obsolete. The Ehcache_failsafe.xml is set to 120 seconds.
Timetoliveseconds: Idle No access time, defaults to 0, never obsolete. The Ehcache_failsafe.xml is set to 120 seconds.
Emigration algorithm: If there are many valid caches after the failure algorithm, then the purge algorithm is performed. The purge algorithm consists of two parameters:
Memorystoreevictionpolicy: Defaults to LRU (most recent minimum access), another advanced first Out (FIFO), minimum number of visits (LFU)
Overflowtodisk (required) is true, the purged cache is persisted to disk, otherwise it will be humanely destroyed.