Caching Issues (Key)

Cache update

  • problem
    • mysql and redis are two separate systems, in a concurrent environment, it can not be updated to ensure consistency
  • Solution
    • Distributed Lock (redis-setnx) / serial processing using message queues
      • Disadvantage of poor concurrency
    • When updating data, the first written mysql, and then delete the cache facebook
      • Mainly used for a data object (Update less)
      • The main data set or update the cache (updated more frequently queried high cost)

Cache penetration

  • problem
    • Hackers will take the initiative to access the data in the database does not exist, the cache will be penetrated, direct access to the database, resulting in pressure to access the database becomes larger
  • Solution
    • For the data in the database does not exist, it also set a default value in the cache expiration time will be shorter general
    • Some filtering rules may be provided, such as the Bloom filter (algorithm for determining whether the data contained in the collection), all possible values ​​of input filters, If no direct return None, probability manslaughter
  • Bloom filter (expand)

    pip install pybloomfiltermmap3

Cache avalanche

  • problem
    • If a large cache data expired at the same time, then it is likely a cache collective failure will lead to direct all requests to access the database, the database resulting in excessive pressure
  • Solution
    • When you set the expiration time, add a random value, so that the expiration time for a certain degree of dispersion
    • Multi-level cache way to deal with
    • Using the lock / queues form

Guess you like

Origin www.cnblogs.com/oklizz/p/11420234.html