Best way to invalidate a number of memcache keys using standard php libraries?

后端 未结 3 909
梦如初夏
梦如初夏 2021-02-04 18:56

I have a database with files which can be searched, browsed and have multiple copies on multiple servers.

I cache searches, browse pages and server locations (urls). Say

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 19:43

    Having come accross the comment here, which explains the logic of evicting existing keys, I believe tags can be implemented reliable by the version flags approach mentioned in: PHP memcache design patterns

    I actually implemented this logic once already, but discarded it as unreliable due to memcache eviction of elements before they expire. You can find my initial implementation here. I do however, believe this is a reliable tags pattern because:

    • On cache object retrieval, the object is moved on top of the LRU stack
    • All tags/flags are retrieved right after the cache object
    • If a flag is evicted, any item containing this flag would have been evicted just before
    • Incrementing a flag returns the new value in the same operation, avoiding write concurrency. If a second thread is incrementing the same flag before the cache object is written, it is by definition invalid already

    Please correct me if I'm wrong! :-)

提交回复
热议问题