Caching policy common errors

  1. When should you update the cache

    Should read data from the database, and then update the cache, the data is read from the cache, you do not need to re-write cache, a common mistake is to update the cache every access interfaces, so, if the interface has been traffic, then the data in the db, it has not been updated chance, every visit, gave continued on time

  2. When data is updated, the need to update the cache synchronization

    Can be updated, but can not guarantee double write will be successful, so the presence of the cache, there is no way to avoid db and cache inconsistencies, simultaneous update, only alleviate inconsistencies, can not be completely avoided

  3. To add a redis mysql table cache, when data modification, there are two general schemes

    i. the first to write mysql, and then update the cache

    ii. to update cache, write mysql

    Which one is more reasonable

      Both programs have two steps, each step there is the possibility of error, Option 2, there is a problem, that is, after deleting redis success, while other threads might access the data, and write data back to the old will redis will lead to inconsistencies, we can only choose a program

    Cache brings complexity is not low, and once introduced into the cache coherence there is no way to avoid the problem, now based on the level db / rocks db kv distributed storage engine, the performance has been close to redis, and it It provides a persistent feature in many business scenarios directly, instead of mysql + redis, and there will be no performance problems, but also more compact solution than mysql + redis

https://github.com/XiaoMi/pegasus

https://github.com/alibaba/tair

Guess you like

Origin www.cnblogs.com/xsirfly/p/12193499.html