开发者

(php) Any patterns around to help with memcache invalidation routine?

开发者 https://www.devze.com 2022-12-19 16:07 出处:网络
some cached elements of my project are stored in memcache. I\'m using memcache tagging mechanism (not native, of course) to simplify cache invalidation control. Everything is ok, but project is growin

some cached elements of my project are stored in memcache. I'm using memcache tagging mechanism (not native, of course) to simplify cache invalidation control. Everything is ok, but project is growing, number of controllers and models is growing and it is becoming really difficult to support cache invalidation cont开发者_高级运维rol. Unfortunately, it is a common situation to forget invalidate cache... :( Is there any code patterns helping to avoid it?

It would be really great if I could separate memcache invalidation routine from model or controller.

Thank you.


Not sure if this is what you are looking for

function update_foo(int userid, string dbUpdateString) {
     result = db_execute(dbUpdateString);
     if (result) {
         data = createUserDataFromDBString(dbUpdateString);
         memcached_set("userrow:" + userid, data);
     }
 }

This call would update the currently cached data to match the new data in the database, assuming the database query succeeds.

See http://en.wikipedia.org/wiki/Memcached

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号