Update documentation for Model::_readDataSource()

Update sample code to generate unique keys based on association
conditions as well. Because association conditions are not part of the
'query' they need to be handled separately.

Refs #8346
This commit is contained in:
mark_story 2016-02-26 12:39:29 -05:00
parent 31b3f39b67
commit 1709f54e38

View file

@ -3011,15 +3011,15 @@ class Model extends Object implements CakeEventListener {
*
* ```
* protected function _readDataSource($type, $query) {
* $cacheName = md5(json_encode($query));
* $cache = Cache::read($cacheName, 'cache-config-name');
* if ($cache !== false) {
* return $cache;
* }
* $cacheName = md5(json_encode($query) . json_encode($this->hasOne) . json_encode($this->belongsTo));
* $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;
* $results = parent::_readDataSource($type, $query);
* Cache::write($cacheName, $results, 'cache-config-name');
* return $results;
* }
* ```
*