Whats the best way to manage keys (in memcache ) to prevent stale cached values?

前端 未结 6 1489
忘了有多久
忘了有多久 2021-01-30 15:01

Ive recently implemented memcache on my site which has been under heavy mysql load (mysql was as optimized as I could make it). It solved all my load issues, and site is running

6条回答
  •  礼貌的吻别
    2021-01-30 15:36

    cache invalidation is a big problem

    "There are only two hard problems in Computer Science: cache invalidation and naming things."

    I will give you a few ideas that will lead you to full solution as there is no genral solution for all use case..

    • read about varnish esi and X-Article-id https://www.varnish-software.com/blog/advanced-cache-invalidation-strategies
    • use nginx ssi
    • keep trackes of all your items in the cache so if you cache 100 forum message store each of the messages id in db so you have something like lastMessages contain messages: 1,2,550,123 etc.. now when any of the items get updated search where its store and purge them one by one(or rebuild them and store again)
    • its like the same solution but instead of each cache item know what its store, each model should know where its store

提交回复
热议问题