Ehcache study notes--initial knowledge of Ehcache

Source: Internet
Author: User

1. Ehcache's main features and cluster scenarios

EHCache EHCache is a pure Java in-process cache, the default cacheprovider in Hibernate, minimal dependencies, comprehensive documentation and testing, the latest version is 2.0.1. Caching is applied to multiple domains and functions, Ehcache can be applied to database access caches, secure authentication caches, web caches, soap and RESTFul service caches, application persistent object caches, and distributed caches.

(1) The main features of EhCache are:

a) fast; b) simple; c) multiple caching strategies;

d) Cache data has two levels: memory and disk, so there is no need to worry about capacity issues;

e) The cached data is written to disk during the virtual machine restart;

f) Distributed caching can be done through RMI, pluggable APIs, etc.;

g) A listening interface with cache and cache manager;

h) Support multi-cache manager instances, and multiple cache areas for one instance;

i) Provide cache implementation of Hibernate;

(2) EhCache from 1.7, support five cluster scenarios, respectively: a) Terracotta b) RMI c) JMS D) JGroups e) EhCache Server

2. Hierarchical model of Ehcache

Ehcache class hierarchy model is mainly three layers, the topmost is the CacheManager, he is the entrance of Operation Ehcache. We can get a list of Cachemanger by Cachemanager.getinstance () or create a new Cachemanger by Cachemanger's constructor. Each CacheManager is managed with multiple caches. Each Cache is associated with multiple Element in a Hash-like manner. Element (Key-value pair) is where we store the content to be cached.

3. Hibernate's Level two cache policy

The general process for Hibernate's level two cache strategy is as follows:

1) When a condition is queried, always issue a SELECT * FROM table_name where .... (select all fields) such SQL statements query the database and get all the data objects at once.

2) Put all the obtained data objects into the second level cache based on the ID.

3) When Hibernate accesses the data object according to the ID, it is first checked from the Session cache, and if the level two cache is configured, it is checked from the level two cache, and the database is not found, and the result is placed in the cache by ID.

4) Update the cache while deleting, updating, and adding data. Hibernate's level two cache policy, which is a cache policy for ID queries, has no effect on conditional queries. To do this, Hi bernate provides query Cache for conditional queries.

4. Ehcache's three emptying strategies

(1) Fifo,first in first out, this is the most familiar, FIFO.

(2) LFU, less frequently used, is the strategy used in the above example, a straightforward point is to say that has been at least used. The cached element has a hit attribute, and the least hits value is cleared out of the cache.

(3) Lru,least recently used, the least recently used, the cached element has a timestamp, when the cache capacity is full, and the need to make room to cache the new elements, then the existing cache elements of the current time stamp is the furthest away from the present element will be cleared cache.

Ehcache study notes--initial knowledge of Ehcache

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.