mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-06-01 04:13:33 +00:00
Implementing a persitent method cache for DboSource, using a stronger hashing algorithm to ensure unique keys
This commit is contained in:
parent
ca0a7e4271
commit
762ebd4b93
1 changed files with 27 additions and 7 deletions
|
@ -246,6 +246,14 @@ class DboSource extends DataSource {
|
||||||
*/
|
*/
|
||||||
public $fieldParameters = array();
|
public $fieldParameters = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether there was a change on the cached results on the methods of this class
|
||||||
|
* This will be used for storing in a more persistent cache
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $_methodCacheChange = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -764,9 +772,13 @@ class DboSource extends DataSource {
|
||||||
if ($this->cacheMethods === false) {
|
if ($this->cacheMethods === false) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
if (empty($this->methodCache)) {
|
||||||
|
$this->methodCache = Cache::read('method_cache', '_cake_core_');
|
||||||
|
}
|
||||||
if ($value === null) {
|
if ($value === null) {
|
||||||
return (isset($this->methodCache[$method][$key])) ? $this->methodCache[$method][$key] : null;
|
return (isset($this->methodCache[$method][$key])) ? $this->methodCache[$method][$key] : null;
|
||||||
}
|
}
|
||||||
|
$this->_methodCacheChange = true;
|
||||||
return $this->methodCache[$method][$key] = $value;
|
return $this->methodCache[$method][$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2167,17 +2179,15 @@ class DboSource extends DataSource {
|
||||||
if (empty($alias)) {
|
if (empty($alias)) {
|
||||||
$alias = $model->alias;
|
$alias = $model->alias;
|
||||||
}
|
}
|
||||||
|
$virtualFields = $model->getVirtualField();
|
||||||
$cacheKey = array(
|
$cacheKey = array(
|
||||||
$model->useDbConfig,
|
|
||||||
$model->table,
|
|
||||||
array_keys($model->schema()),
|
|
||||||
$model->name,
|
|
||||||
$model->getVirtualField(),
|
|
||||||
$alias,
|
$alias,
|
||||||
|
$model->alias,
|
||||||
|
$virtualFields,
|
||||||
$fields,
|
$fields,
|
||||||
$quote
|
$quote
|
||||||
);
|
);
|
||||||
$cacheKey = crc32(serialize($cacheKey));
|
$cacheKey = md5(serialize($cacheKey));
|
||||||
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
|
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -2191,7 +2201,6 @@ class DboSource extends DataSource {
|
||||||
$allFields = $allFields || in_array('*', $fields) || in_array($model->alias . '.*', $fields);
|
$allFields = $allFields || in_array('*', $fields) || in_array($model->alias . '.*', $fields);
|
||||||
|
|
||||||
$virtual = array();
|
$virtual = array();
|
||||||
$virtualFields = $model->getVirtualField();
|
|
||||||
if (!empty($virtualFields)) {
|
if (!empty($virtualFields)) {
|
||||||
$virtualKeys = array_keys($virtualFields);
|
$virtualKeys = array_keys($virtualFields);
|
||||||
foreach ($virtualKeys as $field) {
|
foreach ($virtualKeys as $field) {
|
||||||
|
@ -3123,4 +3132,15 @@ class DboSource extends DataSource {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for storing in cache the results of the in-memory methodCache
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __destruct() {
|
||||||
|
if ($this->_methodCacheChange) {
|
||||||
|
Cache::write('method_cache', $this->methodCache, '_cake_core_');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue