Update:Remora Database/Object Caching
In 425315/r18173, a new object-based memcaching framework landed. This page outlines the basic concepts and use instructions.
Basic concepts
The basic idea behind the caching framework is the fact that instead of letting the controllers do a lot of data manipulation, we push most of this work into the models (where it belongs, arguably). So we have, or need to make, model methods along the line of:
function getMyObject($id, $other, $stuff) { // switch off automatic query caching (1) $this->caching = false; // build unique (but arbitrary) identifier for this object (2) $identifier = array("addon:$id", $other, $stuff); // return cached object if it exists (3) if ($c = $this->Cache->readCacheObject($identifier)) return $c; // build result array (4) $myobject = $this->findById($id); // ... do some other magic if needed // cache that object (5) $this->writeCacheObject($identifier, $myobject, $expirationlists, $seconds_to_cache); // the rest $this->caching = true; return $myobject; }
This will cache data object-wise. An example of how this looks can be found in the Addon model, getAddon().
When we wrote the cache object (5), we defined one or more (arbitrary but unique) expiration list names along the lines of "addon:5" or "version:12". Each of these lists is going to contain a number of cached object IDs that are related and can be expired together. Now at write time, we need to mark one or more of these lists for instant expiration. This is usually done in the afterSave() callback of a model (example: Addon model), but can be done anywhere else if wanted:
function afterSave() { $this->Cache->markListForFlush("addon:{$this->id}"); }
This marks the "addon:$id" list for flushing; the actual flushing of the objects is then performed automatically in the app_controller's afterFilter() callback. No additional action is needed.
Specifics
= 1: switch off automatic query caching
If we don't switch off the automatic query caching, the objects will be invalidated, but the queries to regenerate the object would come from cache, defeating the purpose of the expiration in the first place.
2: Identifier
Each object is identified by a unique string or array. APP and LANG are added automatically, so in the model we can use