Analysis on ehcache Cache

Source: Internet
Author: User

Ehcache is a cache management class library that uses Java to implement complex and high-speed thread-safe usage. ehcache provides memory and disk file storage, as well as a variety of sensitive cache management solutions such as the distributed storage architecture. At the same time, ehcache is openSource codeThe project adopts the relatively loose Apache license V2.0 as the authorization style pattern and is widely used in hibernate,
Other open source systems such as spring and cocoon.

The class model of ehcache is secondary to three layers, and the lowest layer is cachemanager, which is the import of ehcache. We can get a single cachemanager through cachemanager. getinstance (), or create a new cachemanager through the cachemanager schema function. Each cachemanager manages multiple caches. Each cache is in a hash format and is associated with multiple elemenat. Element is the center where we store the content to be cached.

Ehcache's refresh strategy is to use lazy evict's style pattern to record a put effort when the cache is put, at the same time as the set TTL compared to the ehcache cache 3 clearing strategy: 1 FIFO, first 2 LFU, at least used, the cache element has a hit attribute, the minimum hit value will be cleared out of the cache. 3
LRU, recently used at least, the cached element has a timestamp. When the cache capacity is full, and the need to free up the center to cache new elements, the elements with the farthest timestamp in the existing cache will be removed from the cache. The event handler can be considered as adding a event listener to the cachemanager. When a cache is added or deleted to the cachemanager, the event handler will lose notice. To configure the disposal of equipment and decoration, the ehcache configuration file is required.

Ehcache parameter settings and equipment: maxinmemory-sets the maximum value of the object created in the memory. Eternal-set whether an element (in-Memory Object) can reside forever. If yes, the timeout limit will be neglected and the elements will never die. Timetoidleseconds-set the progress time before an element dies. That is, before the death of an element, the maximum distance between the two visits. This is not valid only when the element is not a permanent resident (Note: setting this attribute is useless if the object is permanently extinct ). If the value is
0 means that the progress of the element can be infinite. Timetoliveseconds-sets the life time before the elements die. That is, the maximum time distance between the construction and the extinction of an element. This is not valid only when the element is not a permanent resident. Overflowtodisk-sets whether the elements can be written to the disk when the cache in the memory reaches the maxinmemory limit.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.