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
精彩评论