tags:

views:

40

answers:

1

Hello,

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 control. 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.

A: 

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

Ole Media
Yeah, this code is already implemented in my project and even more over. But it is not what I'm looking for...Thank you for your comment.
Kirzilla
An alternative approach would be to invalidate the cache with the memcached delete function.
Ole Media
@Ole Media, sometimes we need to delete some memcache keys, but we don't really know what is exact key names. We solve this problem by tagging memcached keys.
Kirzilla