Say if you want to allow a user to be able to delete some data, but typically it is static and good for caching. Is there a way to remove that value from the key so you can keep everything else cached and get rid of what the user wanted deleted? The key would be an array of many arrays. The arrays hold the info for the item like id, user name, title, etc. and would want to remove one of those arrays if the user wants to delete.
Example code:
Storing stuff:
$cachedData = $this->memcache->get($this->key);
if($cachedData === false){
$cachedData = array();
$sql = "SELECT id, name FROM table LIMIT 100";
$res = mysql_query($sql);
while($rec = mysql_fetch_assoc($res)){
$cachedData[] = $rec;
}
// cache for 10 minutes
$this->memcache->set($this->key, $cachedData, 0, 600);
}
It’s basically right from google code example.
The only way to do this is to read the key’s value into a variable, modify the contents of that variable, and then write the entire key back to memcached.
memcached operates completely at the top-level key:value layer; it doesn’t care nor understand what you put in it as values. As far as it’s concerned, that “array of arrays” you’re putting in as a value is just another string.