cakephp/cakephp — pull request #1123 by dogmatic69 (2013-02-09 16:22:33+00:00)
Title: Breaking out the find so that it can be easily overloaded for caching

Before this commit you have to do some hacks to cache model finds easily. When using custom find methods like `find('foo')` => `_findFoo(...)` it is common for the method to adjust the query params.

Trying to cache a query using a hash of the query params :

/** Overloaded find() */
function find($type, $query) {
$query = $this->_beforeFind($query); // $query gets modified by custom finds
$cacheKey = $type . '_' . md5(selialize($query));

$cache = Cache::read($cachKey, 'my_cache');
if ($cacheKey !== false) {
return $cache;
}

$results = $this->_afterFind($type, $query); // chance to cache the results
Cache::write($cacheKey, $results, 'my_cache');

return $results;
}

Before this commit you either have to completely overload find and rewrite it in the AppModel or call the before to get the modified `$query` and let cake run the before again.