Cache penetration Concept
Access to a nonexistent key, the cache does not work, the request will penetrate into the DB, when the traffic is large, the db will be hung off.
Solution Solutions
Using the bitmap filter, a large enough to store the key that may be accessed, the nonexistent key is filtered directly;
Access key does not query the value in db, also writes null values to the cache, but can set a shorter expiration time.
Cache Avalanche Concept
A large number of keys set the same expiration time, resulting in the cache at the same time all failed, resulting in a large amount of instantaneous db requests, pressure surges, causing avalanches.
Solution Solutions
You can set the expiration time for the cache by adding a random value time, so that each key's expiration time is distributed, and will not fail at the same time.
Cache Breakdown Concept
An existing key, at the moment the cache expires, there are a large number of requests, these requests will penetrate into the db, resulting in a large number of instantaneous DB requests, pressure surges.
Solution Solutions
Before accessing the key, use SETNX (set if not exists) to set another short-term key to lock the access of the current key, and then delete the short-term key at the end of the visit.
Cache penetration, Cache breakdown, Cache avalanche Concepts and solutions