Cache traversal and Cache avalanche

Source: Internet
Author: User

What is cache penetration through caching? The general cache system is to follow the key to cache the query, if there is no corresponding value, it should go to the backend system lookup (such as DB). If the value of key corresponds to a certain non-existent, and a large number of concurrent requests for the key, it will cause great pressure on the backend system. This is called cache penetration. How to avoid it? 1: The case of NULL query results is also cached, the cache time is set a little bit shorter, or the key corresponding to the data insert after the cache cleanup. 2: Filter The key that does not exist. All possible keys can be placed in a large bitmap, which is filtered by the bitmap when queried. "It doesn't feel like a lot." Cache avalanche What is a cache avalanche? When a cache server restarts or a large number of caches fail at a certain time period, it can also put a lot of pressure on back-end systems (such as DB) when they fail. How to avoid it? 1: After the cache fails, the number of threads that read the database write cache is controlled by a lock or queue. For example, a key allows only one thread to query the data and write the cache, and other threads wait. 2: Different keys, set different expiration time, so that the cache fails to the point of time as evenly as possible. 3: Do two-level cache, A1 for the original cache, A2 for the copy cache, A1 failure, can access A2,A1 cache expiration time set to short-term, A2 set to a long-term (this point to supplement) distributed cache system distributed cache system problem Cache consistency problem

1: The consistency of the cache system with the underlying data. This is especially important when the underlying system is "readable and writable".

2: Consistency between caches that have inheritance relationships. To maximize cache hit rates, the cache is also layered: global cache, Level two cache. They are in an inheritance relationship. The global cache can have a level two cache to make up.

3: Consistency between multiple cache replicas. In order to ensure the high availability of the system, the cache system is often connected to two sets of storage systems (such as MEMCACHE,REDIS, etc.)

Cache penetration and cache avalanche are described above. There are two strategies for retiring cache data: (1) periodically to clean up expired caches. (2) When a user requests to come over, and then determine whether the cache used by the request expires, expired, the underlying system to get new data and update the cache. Both have advantages and disadvantages, the first drawback is to maintain a large number of cache key is more troublesome, the second disadvantage is that every time the user request to judge the cache failure, the logic is relatively complex, the specific use of which scheme, we can be based on their own application scenarios to weigh. 1. Estimated expiry time 2. Version number (must be monotonically incremented, timestamp is the best choice) 3. Provides an interface to manually clean up the cache.

Http://www.cnblogs.com/fidelQuan/p/4543387.html

Cache traversal and Cache avalanche (RPM)

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.