Cache policy three elements: Cache Hit rate cache update policy maximum cache capacity. The standard for measuring a cache scenario is: Cache Hit ratio. The higher the cache hit rate, the better the caching method is designed.
The relationship between the three is: when the cache reaches the maximum cache capacity, the cache update policy is triggered, and the cache update policy affects the cache hit ratio. As you can see, caching scenarios depend on the maximum number of settings in the cache and the selection of cache update policies.
For frequently changing data, it is not suitable for caching. For static, read-write high (generally more than 10:1) of the data cache.
The common cache update policies are:
1 FIFO queue, first-in, FIFO, typical application: MySQL's query cache, using this simple cache update strategy
2 LFU: Minimum use, with counter implementation
3 LRU: Not used for the longest time, with counters and queues
For Redis, when MaxMemory is reached, there are five options to choose from, depending on the scenario, which strategy removes the key:
volatile-lru 采用LRU算法删除带有expire的key(默认)allkeys-lru 采用LRU算法删除任意keyvolatile-random 任意删除带有expire的keyallkeys-random 删除任意keyvolatile-ttl 删除最接近expire的keynoeviction 不删除,直接对写命令返回错误
Redis as Cache