Introduction to EhCache Caching system
EhCache is a pure Java in-process caching framework, with fast, lean and so on, is the default Cacheprovider in Hibernate.
The following figure is the location of the EhCache in the application:
Figure 1. EhCache Application Architecture Diagram
The main characteristics of EhCache are:
Fast
Simple
multiple caching strategies;
Cache data has level two: memory and disk, so there is no need to worry about capacity issues;
The cached data is written to disk during the restart of the virtual machine;
Distributed caching can be done by means of RMI, pluggable APIs, etc.
A listening interface with cache and cache manager;
Support for multiple cache manager instances, as well as multiple cache regions for an instance;
Provide the Hibernate cache implementation;
Wait a minute...
Because EhCache is a caching system in the process, once the application is deployed in a clustered environment, each node maintains its own cached data, and when a node updates the cached data, the updated data cannot be shared among other nodes, which not only reduces the efficiency of the node's operation, but also causes the data to be unsynchronized. For example, a Web site uses a, b two nodes as a cluster deployment, when the A-node cache is updated, and the B-node cache has not been updated may appear when the user browsing the page, one will be updated data, one is not yet updated data, although we can also through the session Sticky Technology to lock users on a node, but for systems that are more interactive or are not WEB-style, session Sticky is clearly not a good fit. So we need to use the EhCache cluster solution.