Cache breakdown

Cache breakdown refers to the query of data in a database with high concurrency, but because there is no data in the cache, a large number of database queries are made at the same time, resulting in excessive database pressure. Solution: 1) Distributed locking mechanism can be added to solve the problem. 2) Hotspot data never expires.Copy the code

The cache to penetrate

Cache penetration refers to accessing data that does not exist in a database. Because the database does not exist, and the result of the database query is null and there is no cache, the database is overloaded with queries every time. Solution: 1) You can perform verification at the interface layer. For example, if the ID of the interface is <0, the interface is not queried. 2) Cache null results as well. Cache for a while.Copy the code

Cache avalanche

Cache avalanche refers to a time when a large number of cache expires, resulting in a large number of requests to access the database solution: 1) add a random number to the cache value. 3) You can set the cluster mode of redis cache, so that the cache is distributed on different machines, reducing the pressure.Copy the code