mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Change cacheMethodFilters to be a method
This commit is contained in:
parent
58cc9b4596
commit
71535d2d2c
1 changed files with 15 additions and 43 deletions
|
@ -60,49 +60,13 @@ class DboSource extends DataSource {
|
|||
public static $methodCache = array();
|
||||
|
||||
/**
|
||||
* Whether or not to cache the results of DboSource::name(), DboSource::fields() and DboSource::conditions()
|
||||
* Whether or not to cache the results of DboSource::name() and DboSource::conditions()
|
||||
* into the memory cache. Set to false to disable the use of the memory cache.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $cacheMethods = true;
|
||||
|
||||
/**
|
||||
* Filters to apply to the results of DboSource::name(), DboSource::fields() and DboSource::conditions().
|
||||
* When the filter function for a given method does not return true then the result is not added to the memory cache.
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* ```
|
||||
* array(
|
||||
* // For method fields, do not cache values that contain floats
|
||||
* 'fields' => function ($value) {
|
||||
* $hasFloat = preg_grep('/(\d+)?\.\d+/', $value);
|
||||
*
|
||||
* return count($hasFloat) === 0;
|
||||
* },
|
||||
* // For method name, do not cache values that have the name floats
|
||||
* 'name' => function ($value) {
|
||||
* return preg_match('/^`rating_diff`$/', $value) !== 1;
|
||||
* }
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* or
|
||||
*
|
||||
* ```
|
||||
* array(
|
||||
* // For method fields, do not cache any values
|
||||
* 'fields' => function () {
|
||||
* return false;
|
||||
* },
|
||||
* )
|
||||
* ```
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $cacheMethodFilters = array();
|
||||
|
||||
/**
|
||||
* Flag to support nested transactions. If it is set to false, you will be able to use
|
||||
* the transaction methods (begin/commit/rollback), but just the global transaction will
|
||||
|
@ -822,18 +786,26 @@ class DboSource extends DataSource {
|
|||
if ($value === null) {
|
||||
return (isset(static::$methodCache[$method][$key])) ? static::$methodCache[$method][$key] : null;
|
||||
}
|
||||
|
||||
$methodFilterExists = (
|
||||
isset($this->cacheMethodFilters[$method]) && is_callable($this->cacheMethodFilters[$method])
|
||||
);
|
||||
if ($methodFilterExists && !call_user_func($this->cacheMethodFilters[$method], $value)) {
|
||||
if (!$this->cacheMethodFilter($method, $key, $value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$this->_methodCacheChange = true;
|
||||
return static::$methodCache[$method][$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters to apply to the results of `name` and `fields`. When the filter for a given method does not return `true`
|
||||
* then the result is not added to the memory cache.
|
||||
*
|
||||
* @param string $method Name of the method being cached.
|
||||
* @param string $key The key name for the cache operation.
|
||||
* @param mixed $value The value to cache into memory.
|
||||
* @return bool Whether or not to cache
|
||||
*/
|
||||
public function cacheMethodFilter($method, $key, $value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a quoted name of $data for use in an SQL statement.
|
||||
* Strips fields out of SQL functions before quoting.
|
||||
|
|
Loading…
Add table
Reference in a new issue