Distributed Cache (b)

Distributed cache: Ehcache, Memcached, Redis and other caching framework, the main features of what is? What are business scenarios apply to?

 EHcache:  is the java platform relatively good caching framework, starting from the hibernate cache widely used up. Data may be scalable to several G bytes to hundreds of nodes can provide the most complete implementation of JSR107 JCACHE API. Node discovery, redundancy and listeners can plug-in technology. At the same time, it provides a number of post-processing mechanism for cache events, both flexibility and scalability. EHcache widely used in many enterprise applications.

(A secondary cache is integrated MyBatis Ehcache)

1. Features:

 

  • Access speed is very fast, very good performance.
  • You can apply various caching strategies.
  • Hierarchical caching, the user can specify which data is cached in the hard disk, which data is cached in memory.
  • By RMI, etc. can be inserted into the distributed API caches.
  • Listening with a cache and Cache Manager interface.
  • Cache Manager supports multi-instance, and multiple instances of a cache area.
  • Hibernate provides a default cache implementation.
2. cached data elimination strategy

FIFO: First In First Out
LFU: the least used, the element has a cache hit attribute, the cache hit value will be cleared minimal.
LRU: Least Recently Used caching elements have a time stamp, when the cache capacity is full, but need to make room for the new element when the cache, then the existing cache elements timestamp from the current time to the farthest element the cache is cleared.

3. Data expiration policy 

Ehcache uses a lazy elimination mechanism, every time you go into the data cache, will keep a time when you want to read and set the time to do the comparison to determine whether the TTL expired.

4.Ehcache how to behave in the case of clusters, distributed
1) RMI multicast.
When the cache is changed, ehcache RMI UDP multicast packets sent to the multicast IP address and port number.
Defects: Ehcache multicast done more primary, basic function is to implement (such as a HUB simple, two single attachment server network card, each multicast synchronization between no problem), for complex environments (such as multiple server, each server on multiple address, especially in clusters, there is a cluster address with multiple physical machines, each physical machine with multiple virtual stations and sub-address), it is prone to problems. 

2) P2P mode
Principle: P2P claim Ehcache each node pointing towards the other N-1 nodes.

3) JMS message mode

The core of this model is that a message queue, each application node subscribe to predefined themes, while there is an element node update, the update will be released element to the topic go. Each application server node MQ acquired by listening to the latest data, then update their respective Ehcache cache, Ehcache default support ActiveMQ, we can also customize the way the components to achieve a similar Kafka, RabbitMQ.

4) Cache Server mode
works: This mode will exist from the master node.

 

Memcached: is a high-performance, distributed memory object caching system, by maintaining a unified giant hash table in memory, it can be used to store data in various formats, including the results of images, videos, files, and database retrieval Wait. Simply put, it is to call the data into memory, and then read from memory, thus greatly improving the read speed. Memcached object cache support, became the first choice for many Internet applications, especially in highly integrated with mysql database.

 

Redis:  it is an advanced key-value cache and storage systems, the role of important application-level cache. Redis supports master-slave synchronization, perform single-copy tree. Since the full implementation of the publish / subscribe mechanism, so that at the right time from anywhere in the database synchronization tree can subscribe to a channel and receive the full message master server publishing record. Synchronous read operation useful purpose and scalable data redundancy. Redis 3.0 version adds cluster function, can not solve a single point Redis scale of the problem. Redis is the current mainstream Internet application cache architecture

Guess you like

Origin www.cnblogs.com/fanBlog/p/11430091.html