Caching paginated results, purging on update - how to solve?

前端 未结 8 1111
忘掉有多难
忘掉有多难 2021-02-04 18:08

I\'ve created a forum, and we\'re implementing an apc and memcache caching solution to save the database some work.

I started implementing the cache layer with keys like

8条回答
  •  没有蜡笔的小新
    2021-02-04 18:43

    I've managed to solve this by extending the memcache class with a custom class (say ExtendedMemcache) which has a protected property which will contain a hash table of group to key values.

    The ExtendedMemcache->set method accepts 3 args ($strGroup,$strKey, $strValue) When you call set, it will store the relationship between $strGroup, and $strKey, in the protected property and then go on to store the $strKey to $strValue relationship in memcache.

    You can then add a new method to the ExtendedMemcache class called "deleteGroup", which will, when passed a string, find that keys associated to that group, and purge each key in turn.

    It would be something like this: http://pastebin.com/f566e913b I hope all that makes sense and works out for you.

    PS. I suppose if you wanted to use static calls the protected property could be saved in memcache itself under it's own key. Just a thought.

提交回复
热议问题