Index: branches/5.2.x/core/kernel/utility/cache.php =================================================================== diff -u -N -r16753 -r16772 --- branches/5.2.x/core/kernel/utility/cache.php (.../cache.php) (revision 16753) +++ branches/5.2.x/core/kernel/utility/cache.php (.../cache.php) (revision 16772) @@ -1,6 +1,6 @@ maxCacheDuration = $max_cache_duration; $this->siteKeyName = 'site_serial:' . crc32(SQL_TYPE . '://' . SQL_USER . ':' . SQL_PASS . '@' . SQL_SERVER . ':' . TABLE_PREFIX . ':' . SQL_DB); // get cache handler class to use @@ -125,6 +140,7 @@ $this->cachingType = $handler->getCachingType(); $this->debugCache = $handler->getCachingType() == CACHING_TYPE_MEMORY && $this->Application->isDebugMode(); $this->_storeStatistics = defined('DBG_CACHE') && DBG_CACHE; + $this->cachePrefix = $this->_cachePrefix(); if ( $this->_storeStatistics ) { // don't use FileHelper, since kFactory isn't ready yet @@ -145,15 +161,20 @@ } /** - * Stores value to cache + * Stores new $value in cache with $name name. * - * @param string $name - * @param mixed $value - * @param int $expiration cache record expiration time in seconds - * @return bool + * @param string $name Key name to add to cache. + * @param mixed $value Value of cached record. + * @param integer|null $expiration When value expires (0 - doesn't expire). + * + * @return boolean */ - function setCache($name, $value, $expiration) + function setCache($name, $value, $expiration = null) { + if ( $expiration === null ) { + $expiration = $this->maxCacheDuration; + } + // 1. stores current version of serial for given cache key $this->_setCache($name . '_serials', $this->replaceSerials($name), $expiration); $this->storeStatistics($name, 'W'); @@ -185,15 +206,20 @@ } /** - * Stores value to cache (only if it's not there already) + * Stores value to cache (only if it's not there already). * - * @param string $name - * @param mixed $value - * @param int $expiration cache record expiration time in seconds - * @return bool + * @param string $name Key name to add to cache. + * @param mixed $value Value of cached record. + * @param integer|null $expiration When value expires (0 - doesn't expire). + * + * @return boolean */ - function addCache($name, $value, $expiration) + function addCache($name, $value, $expiration = null) { + if ( $expiration === null ) { + $expiration = $this->maxCacheDuration; + } + // 1. stores current version of serial for given cache key $this->_setCache($name . '_serials', $this->replaceSerials($name), $expiration); @@ -457,7 +483,7 @@ $site_key = $this->_cachePrefix(true); - $this->_handler->set($site_key, $this->_handler->get($site_key) + 1); + $this->_handler->set($site_key, $this->_handler->get($site_key) + 1, 0); } /** @@ -473,7 +499,7 @@ } // add site-wide prefix to key - return $this->_cachePrefix() . $name; + return $this->cachePrefix . $name; } /** @@ -599,24 +625,24 @@ /** * Stores value in cache * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - abstract public function set($name, $value, $expiration = 0); + abstract public function set($name, $value, $expiration = null); /** * Stores value in cache (only if it's not there already) * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - abstract public function add($name, $value, $expiration = 0); + abstract public function add($name, $value, $expiration = null); /** * Deletes key from cach @@ -686,27 +712,27 @@ /** * Stores value in cache * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function set($name, $value, $expiration = 0) + public function set($name, $value, $expiration = null) { return true; } /** * Stores value in cache (only if it's not there already) * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function add($name, $value, $expiration = 0) + public function add($name, $value, $expiration = null) { return true; } @@ -761,8 +787,8 @@ $this->_handler->addServer($server, $port); } - // verify, that memcache server is working - if ( !$this->_handler->set('test', 1) ) { + // Verify, that memcache server is working. + if ( !$this->set('test', 1) ) { $this->_enabled = false; } } @@ -783,13 +809,13 @@ /** * Stores value in cache * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function set($name, $value, $expiration = 0) + public function set($name, $value, $expiration = null) { // 0 - don't use compression return $this->_handler->set($name, $value, 0, $expiration); @@ -798,13 +824,13 @@ /** * Stores value in cache (only if it's not there already) * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function add($name, $value, $expiration = 0) + public function add($name, $value, $expiration = null) { // 0 - don't use compression return $this->_handler->add($name, $value, 0, $expiration); @@ -866,7 +892,7 @@ } // Verify, that memcache server is working. - if ( !$this->_handler->set('test', 1) ) { + if ( !$this->set('test', 1) ) { $this->_enabled = false; } } @@ -892,29 +918,27 @@ /** * Stores value in cache * - * @param string $name Name. - * @param mixed $value Value. - * @param integer $expiration Expiration. + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. * * @return boolean - * @access public */ - public function set($name, $value, $expiration = 0) + public function set($name, $value, $expiration = null) { return $this->_handler->set($name, $value, $expiration); } /** * Stores value in cache (only if it's not there already) * - * @param string $name Name. - * @param mixed $value Value. - * @param integer $expiration Expiration. + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. * * @return boolean - * @access public */ - public function add($name, $value, $expiration = 0) + public function add($name, $value, $expiration = null) { return $this->_handler->add($name, $value, $expiration); } @@ -964,27 +988,27 @@ /** * Stores value in cache * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function set($name, $value, $expiration = 0) + public function set($name, $value, $expiration = null) { return apc_store($name, $value, $expiration); } /** * Stores value in cache (only if it's not there already) * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function add($name, $value, $expiration = 0) + public function add($name, $value, $expiration = null) { return apc_add($name, $value, $expiration); } @@ -1043,27 +1067,27 @@ /** * Stores value in cache * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function set($name, $value, $expiration = 0) + public function set($name, $value, $expiration = null) { return xcache_set($name, $value, $expiration); } /** * Stores value in cache (only if it's not there already) * - * @param string $name - * @param mixed $value - * @param int $expiration - * @return bool - * @access public + * @param string $name Name. + * @param mixed $value Value. + * @param integer|null $expiration Expiration. + * + * @return boolean */ - public function add($name, $value, $expiration = 0) + public function add($name, $value, $expiration = null) { // not atomic operation, like in Memcached and may fail if ( xcache_isset($name) ) {