编程知识 cdmana.com

[November 10] redis cache system common problems and Solutions

Cache penetration

Cache penetration is when the user is in Redis When the cache system queries a piece of data , and MySQL Database and Redis There is no record of this data in the cache . This data is in the Redis If the query is not found in the cache, it will naturally be directed to MySQL Database request for data ,MySQL The database can't get data either , Lead to Redis The cache will always query MySQL database , This will to MySQL Database access creates a lot of pressure

 Cache penetration


Cache penetration solution 1 : Caching empty objects

Caching empty objects

Cache empty objects are user requests for queries Redis Cache and MySQL Data that does not exist in the database ,MySQL The database will return an empty object , This request is associated with an empty object Redis In cache ; When the same user request exists , At this time Redis The cache will hit , The empty object is returned directly from the cache , This can reduce the pressure to access the database , Improve the current database access performance .

  • advantage

    The principle and implementation of cache empty object mechanism is relatively simple ( Code maintenance is easy )

  • shortcoming

    Using cache empty objects for a long time can result in Redis There are a lot of empty objects in the cache , Not only will it take up a lot of memory space , And a lot of resources will be wasted ( It is recommended to set the expiration time of cache empty objects )

    redisCache.put(Integer.toString(id),null,60); // The expiration date is 60s

 Cache penetration cache null object solution


Cache penetration solution 2 : The bloon filter ( recommend )

The bloon filter

The bloon filter is a kind of filter , It's based on the underlying data structure , It is mainly used to determine whether an element is in the collection , Fast running speed . But the bloon filter is not absolutely accurate , There will be a small probability of miscalculation , As long as the parameter setting is reasonable , Its accuracy can be controlled relatively accurately


Solution

Use of Blum filter , Hash all possible data to a binary large enough bitmap in , A certain nonexistent data will be bitmap Intercept , Thus avoiding the query pressure on the underlying database

Bronco .........

版权声明
本文为[Irving the procedural ape]所创,转载请带上原文链接,感谢

Scroll to Top