Redis cache and cache penetrate avalanche

1. What is the cache avalanche?

  For example: Redis can not put all the data is cached, all redis data needs to set the expiration time, and the timing and inert delete delete key to remove the two strategies to expire. If the expiration time of the cached data set is the same, and redis just part of these data are deleted, which resulted in the failure of the entire cache, all requests went to the database.

In short: is our cache database (Redis) hung up, all of the requests have come to the database.

2, how to solve the cache avalanche?

  To the buffer provided in a random expiration time, thus reducing the cache expires at the same time point.

  When redis hung up, it can be divided into three points resolve:

  1) before the incident, to achieve high availability redis, try to avoid the occurrence of hang redis

  2) at the time of the incident, you can set the local cache and limiting mechanisms, the greatest extent possible to prevent the database GG

  3) after the incident, redis persistence, automatically load the data from the disk after the restart, quickly returned to pre-disaster condition.

 

3. What is the cache penetrate?

  Caching refers to penetrate a certain query data does not exist. Because in fault tolerance consideration, when the cache does not have this data, you will find from the database, the database can not be found if it is not saved to the cache. This has resulted in a time that does not exist in the data request are connecting to the database, the database to find the lost meaning of the cache.

In short: the requested data is not a lot of hits in the cache, resulting in the request database are gone.

4, how to solve the cache penetrate?

  Two options:

1) invalid if the requested data does not exist, you can use the Bloom filter (BloomFilter) in advance intercept illegal will not let this request to the database layer.

2) When the requested data is not found, can save the empty object to a cache (typically set a short expiration time), when requested again from the cache can get inside.

 

5. What is double the cache and write the same database?

  When we need to update the data, in many cases it will result in inconsistent data in the database and cache. In theory, as long as you set an expiration time, you will be able to ensure that the data cache and the database is ultimately the same. As long as cached data has expired, it will be deleted, and then read and they will look for data in the database, read data written to the cache.

Guess you like

Origin www.cnblogs.com/in-the-game-of-thrones/p/11495213.html