当前位置:网站首页>Redis cache update strategy actively

Redis cache update strategy actively

2022-08-09 09:58:00 ruochen

  • Cache Aside Pattern: By the caller of the cache, the cache is updated at the same time as the database is updated
  • Read/Write Through Pattern: The cache and the database are integrated into a service, and the service maintains the consistency.The caller calls the service without having to care about cache coherency
  • Write Behind Caching Pattern: The caller only operates the cache, and other threads asynchronously persist the cached data to the database to ensure eventual consistency
  • Comparatively speaking, the Cache Aside Pattern is more reliable
  • There are several issues to consider when manipulating caches and databases - delete cache or update cache?- Update the cache: Update the cache every time the database is updated, and there are many invalid writes - Delete the cache: Invalidate the cache when updating the database, and update the cache when querying (Better) - How to ensure the cache and databaseThe operation succeeds or fails at the same time?(Atomicity) - Monolithic system: transaction control - Distributed system: Using distributed transaction schemes such as TCC - Operation cache or database first?(Thread safety) - Delete the cache first, then operate the database - First operate the database, then delete the cache - Since redis is much faster than MySQL, solution 2 is preferred
    insert image description here
  • The best solution for cache update strategy- Low consistency requirement: Use Redis's own memory elimination mechanism- High consistency requirement: Active update, and take timeout culling as the bottom line - Read operation: - Return directly if the cache hits- If the cache misses, query the database, write to the cache, and set the timeout period. - Write operation: - write to the database first, and then delete the cache - to ensure the atomicity of database and cache operations
原网站

版权声明
本文为[ruochen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/221/202208090943258853.html