Cache Cache penetrate avalanche

1. What is the cache avalanche

     Since the cache invalidation, direct access to a large number of database access, exert enormous pressure on the database and CPU, it can cause serious downtime of the database, the system crashes.

2, how to prevent caching avalanche

     1, an avalanche caused by the direct cause of the cache, the cache is due to the large number of simultaneous failure the same time, so a lot of access may not get the data from the cache to access the database.

           You can make different key, to set a different cache time, so even point cache expiration time distribution.

           Drawback, too much trouble, you develop this feature, developers have asked the caching function of someone else's expiration time

      2, the lock can be used

           For access to the database, you can only access a thread

           Cons: palliative, poor performance, just reduce the pressure on the database access

       3, messaging middleware

           By way messaging middleware, and more like locking manner between the intermediate may correspond to a message queue buffer, each thread locked access to the database with respect to a little more, better performance

       4, by adding a secondary cache way

            One can not find inside, go inside to the secondary query.

           Do secondary cache, cache the original A1, A2 copy is cached, when A1 fails, access to A2, A1 cache expiration time is set short-term, A2 is set for long-term (this point is supplement)

3. What is the cache penetration

     Cache penetration is, every time you access the cache, there is no access to, and then to access the database, the database does not, when a plurality of similar requests, it will cause a lot of pressure on the database.

     This case, when the hacker attacks occur

     Solution: If the database does not return empty, put into the cache, the next query will not access the database, and will reduce the pressure on the database.

     Private  String SIGN_KEY = "$ {NULL}", it can be assumed to be similar to the special string as return values.

 

Guess you like

Origin www.cnblogs.com/pickKnow/p/11314726.html