I understand the need for a function like DB_Get_Cached(“sql string”) that hashes the SQL in order to perform a lookup in memcached for the existence of the data.
function DB_Get_Cached(string SQL)
data = memcache_get_data(md5(SQL))
if (!data)
return DB_Get(SQL)
end if
end function
What is a good method to expand this to handle data invalidation or timeout?
I’m thinking in terms of product pages in an e-commerce site, or user details in their profile.
Thanks
You can use a global version id of some sort in your key. For example, if you had this key to represent the data for product #1234:
Add a version id to the key like this:
Then, when you want to invalidate your cache, simply increment the version id. This will cause all the cache keys to change: