mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #1123 from dogmatic69/model-cache
Breaking out the find so that it can be easily overloaded for caching
This commit is contained in:
commit
ef592363d6
1 changed files with 28 additions and 0 deletions
|
@ -2686,6 +2686,34 @@ class Model extends Object implements CakeEventListener {
|
|||
return null;
|
||||
}
|
||||
|
||||
return $this->_readDataSource($type, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the datasource
|
||||
*
|
||||
* Model::_readDataSource() is used by all find() calls to read from the data source and can be overloaded to allow
|
||||
* caching of datasource calls.
|
||||
*
|
||||
* {{{
|
||||
* protected function _readDataSource($type, $query) {
|
||||
* $cacheName = md5(json_encode($query));
|
||||
* $cache = Cache::read($cacheName, 'cache-config-name');
|
||||
* if ($cache !== false) {
|
||||
* return $cache;
|
||||
* }
|
||||
*
|
||||
* $results = parent::_readDataSource($type, $query);
|
||||
* Cache::write($cacheName, $results, 'cache-config-name');
|
||||
* return $results;
|
||||
* }
|
||||
* }}}
|
||||
*
|
||||
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
|
||||
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
|
||||
* @return array
|
||||
*/
|
||||
protected function _readDataSource($type, $query) {
|
||||
$results = $this->getDataSource()->read($this, $query);
|
||||
$this->resetAssociations();
|
||||
|
||||
|
|
Loading…
Reference in a new issue