Index: branches/RC/core/kernel/utility/cache.php =================================================================== diff -u -N -r8929 -r10494 --- branches/RC/core/kernel/utility/cache.php (.../cache.php) (revision 8929) +++ branches/RC/core/kernel/utility/cache.php (.../cache.php) (revision 10494) @@ -1,23 +1,23 @@ Conn =& $this->Application->GetADODBConnection(); + function kCache() { + parent::kBase(); $this->debugCache = $this->Application->isDebugMode() && constOn('DBG_CACHE'); + + $this->_storage = new CacheStorage(); } /** @@ -29,9 +29,7 @@ */ function setCache($cache_name, $key, $value) { - $cache = $this->Get($cache_name, Array()); - $cache[$key] = $value; - $this->Set($cache_name, $cache); + $this->_storage->set($cache_name, $key, $value); } /** @@ -43,8 +41,7 @@ */ function getCache($cache_name, $key) { - $cache = $this->Get($cache_name, Array()); - $ret = getArrayValue($cache, $key); + $ret = $this->_storage->get($cache_name, $key); $this->setStatistics($cache_name, $key, $ret); @@ -53,14 +50,16 @@ function setStatistics($cache_name, $key, $found) { - if (!$this->debugCache) return true; + if (!$this->debugCache) { + return true; + } - if (!isset($this->statistics[$cache_name])) { - $this->statistics[$cache_name] = Array(); + if (!array_key_exists($cache_name, $this->statistics)) { + $this->statistics[$cache_name] = Array (); } - if (!isset($this->statistics[$cache_name][$key])) { - $this->statistics[$cache_name][$key] = Array(); + if (!array_key_exists($key, $this->statistics[$cache_name])) { + $this->statistics[$cache_name][$key] = Array (); } $status_key = $found ? 'found' : 'not_found'; @@ -73,17 +72,40 @@ function printStatistics() { + $cache_size = strlen(serialize($this->_storage)); + + $this->Application->Debugger->appendHTML('Cache Size: ' . formatSize($cache_size) . ' (' . $cache_size . ')'); + foreach ($this->statistics as $cache_name => $cache_data) { foreach ($cache_data as $key => $value) { - if (!isset($value['found']) || $value['found'] == 1) { + if (!array_key_exists('found', $value) || $value['found'] == 1) { // remove cached records, that were used only 1 or 2 times unset($this->statistics[$cache_name][$key]); } } } - print_pre($this->statistics); + print_pre($this->statistics, 'Cache Statistics:'); } } + class CacheStorage extends Params { + + function set($cache_name, $key, $value) + { + $cache = parent::Get($cache_name, Array()); + $cache[$key] = $value; + + parent::Set($cache_name, $cache); + } + + function get($cache_name, $key) + { + $cache = parent::Get($cache_name, Array()); + $ret = array_key_exists($key, $cache) ? $cache[$key] : false; + + return $ret; + } + } + ?> \ No newline at end of file