Skip to content

Commit

Permalink
Making DboSource::$methodCache a static variable to be able to share …
Browse files Browse the repository at this point in the history
…the cache between multiple instances of the same class
  • Loading branch information
lorenzo committed Jul 18, 2011
1 parent 58282c3 commit a786f4b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -62,7 +62,7 @@ class DboSource extends DataSource {
* @var array
* @access public
*/
public $methodCache = array();
public static $methodCache = array();

/**
* Whether or not to cache the results of DboSource::name() and DboSource::conditions()
Expand Down Expand Up @@ -753,7 +753,8 @@ public function field($name, $sql) {
* @return void
*/
public function flushMethodCache() {
$this->methodCache = array();
$this->_methodCacheChange = true;
self::$methodCache = array();
}

/**
Expand All @@ -772,14 +773,14 @@ public function cacheMethod($method, $key, $value = null) {
if ($this->cacheMethods === false) {
return $value;
}
if (empty($this->methodCache)) {
$this->methodCache = Cache::read('method_cache', '_cake_core_');
if (empty(self::$methodCache)) {
self::$methodCache = Cache::read('method_cache', '_cake_core_');
}
if ($value === null) {
return (isset($this->methodCache[$method][$key])) ? $this->methodCache[$method][$key] : null;
return (isset(self::$methodCache[$method][$key])) ? self::$methodCache[$method][$key] : null;
}
$this->_methodCacheChange = true;
return $this->methodCache[$method][$key] = $value;
return self::$methodCache[$method][$key] = $value;
}

/**
Expand Down

0 comments on commit a786f4b

Please sign in to comment.