Index: branches/5.2.x/core/kernel/application.php =================================================================== diff -u -N -r16761 -r16772 --- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 16761) +++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 16772) @@ -1,6 +1,6 @@ cacheManager->setCache($key, $value, $expiration); + return $this->cacheManager->setCache($name, $value, $expiration); } /** * Stores new $value in cache with $key name (only if it's not there) * - * @param int $key key name to add to cache - * @param mixed $value value of cached record - * @param int $expiration when value expires (0 - doesn't expire) - * @return bool - * @access public + * @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 */ - public function addCache($key, $value, $expiration = 0) + public function addCache($name, $value, $expiration = null) { - return $this->cacheManager->addCache($key, $value, $expiration); + return $this->cacheManager->addCache($name, $value, $expiration); } /** @@ -948,15 +948,15 @@ } /** - * Sets value to database cache + * Sets value to database cache. * - * @param string $name - * @param mixed $value - * @param int|bool $expiration + * @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 void - * @access public */ - public function setDBCache($name, $value, $expiration = false) + public function setDBCache($name, $value, $expiration = null) { $this->cacheManager->setDBCache($name, $value, $expiration); } Index: branches/5.2.x/core/kernel/nparser/nparser.php =================================================================== diff -u -N -r16513 -r16772 --- branches/5.2.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 16513) +++ branches/5.2.x/core/kernel/nparser/nparser.php (.../nparser.php) (revision 16772) @@ -1,6 +1,6 @@ CachingEnabled) { return false; } + // Don't allow creating a non-expiring caches from a template. + if ( (int)$expiration <= 0 ) { + $expiration = null; + } + // remeber DataExists in cache, because after cache will be restored // it will not be available naturally (no tags, that set it will be called) $value .= '[DE_MARK:' . (int)$this->DataExists . ']'; Index: branches/5.2.x/core/kernel/utility/unit_config_reader.php =================================================================== diff -u -N -r16764 -r16772 --- branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 16764) +++ branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 16772) @@ -1,6 +1,6 @@ Application->isCachingType(CACHING_TYPE_MEMORY) ) { - $this->Application->setCache('master:config_files', serialize($this->configFiles)); + $this->Application->setCache('master:config_files', serialize($this->configFiles), 0); } else { - $this->Application->setDBCache('config_files', serialize($this->configFiles)); + $this->Application->setDBCache('config_files', serialize($this->configFiles), 0); } } } Index: branches/5.2.x/core/units/helpers/site_helper.php =================================================================== diff -u -N -r15226 -r16772 --- branches/5.2.x/core/units/helpers/site_helper.php (.../site_helper.php) (revision 15226) +++ branches/5.2.x/core/units/helpers/site_helper.php (.../site_helper.php) (revision 16772) @@ -1,6 +1,6 @@ Conn->Query($sql, 'DomainId'); if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { - $this->Application->setCache('master:domains_parsed', serialize($cache)); + $this->Application->setCache('master:domains_parsed', serialize($cache), 0); } else { - $this->Application->setDBCache('domains_parsed', serialize($cache)); + $this->Application->setDBCache('domains_parsed', serialize($cache), 0); } } } Index: branches/5.2.x/core/kernel/utility/system_config.php =================================================================== diff -u -N -r16691 -r16772 --- branches/5.2.x/core/kernel/utility/system_config.php (.../system_config.php) (revision 16691) +++ branches/5.2.x/core/kernel/utility/system_config.php (.../system_config.php) (revision 16772) @@ -68,6 +68,7 @@ 'ApplicationClass' => 'kApplication', 'ApplicationPath' => '/core/kernel/application.php', 'CacheHandler' => 'Fake', + 'MaxCacheDuration' => 30, 'CmsMenuRebuildTime' => 10, 'DomainsParsedRebuildTime' => 2, 'EditorPath' => '/core/ckeditor/', Index: branches/5.2.x/core/install/install_toolkit.php =================================================================== diff -u -N -r16753 -r16772 --- branches/5.2.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 16753) +++ branches/5.2.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 16772) @@ -1,6 +1,6 @@ systemConfig->get('CacheHandler', 'Misc'); } - $cache_handler = $this->Application->makeClass('kCache'); + $max_cache_duration = 60 * 60 * 24 * $this->systemConfig->get('MaxCacheDuration', 'Misc'); + $cache_handler = $this->Application->makeClass('kCache', array($max_cache_duration)); $cache_handlers = Array ( 'Fake' => 'None', 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) ) { Index: branches/5.2.x/core/install/step_templates/sys_config.tpl =================================================================== diff -u -N -r16435 -r16772 --- branches/5.2.x/core/install/step_templates/sys_config.tpl (.../sys_config.tpl) (revision 16435) +++ branches/5.2.x/core/install/step_templates/sys_config.tpl (.../sys_config.tpl) (revision 16772) @@ -8,6 +8,7 @@ 'ApplicationClass' => Array ('type' => 'text', 'title' => 'Name of Base Application Class', 'section' => 'Misc'), 'ApplicationPath' => Array ('type' => 'text', 'title' => 'Path to Base Application Class file', 'section' => 'Misc'), 'CacheHandler' => Array ('type' => 'select', 'title' => 'Output Caching Engine', 'section' => 'Misc'), + 'MaxCacheDuration' => Array ('type' => 'text', 'title' => 'Maximum Cache Duration (in days)', 'section' => 'Misc'), 'MemcacheServers' => Array ('type' => 'text', 'title' => 'Location of Memcache Servers', 'section' => 'Misc'), 'CompressionEngine' => Array ('type' => 'select', 'title' => 'CSS/JS Compression Engine', 'section' => 'Misc'), 'WebsiteCharset' => Array ('type' => 'text', 'title' => 'Website Charset', 'section' => 'Misc', 'required' => 1), Index: branches/5.2.x/core/kernel/managers/cache_manager.php =================================================================== diff -u -N -r16664 -r16772 --- branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 16664) +++ branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 16772) @@ -1,6 +1,6 @@ settingTableName = TABLE_PREFIX . 'ConfigurationValues'; } } + + $this->maxCacheDuration = 60 * 60 * 24 * kUtil::getSystemConfig()->get('MaxCacheDuration', ''); } + /** * Creates caching manager instance * * @access public */ public function InitCache() { - $this->cacheHandler = $this->Application->makeClass('kCache'); + $this->cacheHandler = $this->Application->makeClass('kCache', array($this->maxCacheDuration)); } /** @@ -344,12 +354,12 @@ $cache_rebuild_by = SERVER_NAME . ' (' . $this->Application->getClientIp() . ') - ' . adodb_date('d/m/Y H:i:s'); if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { - $this->Application->setCache('master:configs_parsed', serialize($cache)); - $this->Application->setCache('master:last_cache_rebuild', $cache_rebuild_by); + $this->Application->setCache('master:configs_parsed', serialize($cache), 0); + $this->Application->setCache('master:last_cache_rebuild', $cache_rebuild_by, 0); } else { - $this->Application->setDBCache('configs_parsed', serialize($cache)); - $this->Application->setDBCache('last_cache_rebuild', $cache_rebuild_by); + $this->Application->setDBCache('configs_parsed', serialize($cache), 0); + $this->Application->setDBCache('last_cache_rebuild', $cache_rebuild_by, 0); } } @@ -510,31 +520,31 @@ } /** - * Stores new $value in cache with $key name + * Stores new $value in cache with $name name. * - * @param int $key key name to add to cache - * @param mixed $value value of cached record - * @param int $expiration when value expires (0 - doesn't expire) - * @return bool - * @access public + * @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 */ - public function setCache($key, $value, $expiration = 0) + public function setCache($name, $value, $expiration = null) { - return $this->cacheHandler->setCache($key, $value, $expiration); + return $this->cacheHandler->setCache($name, $value, $expiration); } /** * Stores new $value in cache with $key name (only if not there already) * - * @param int $key key name to add to cache - * @param mixed $value value of cached record - * @param int $expiration when value expires (0 - doesn't expire) - * @return bool - * @access public + * @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 */ - public function addCache($key, $value, $expiration = 0) + public function addCache($name, $value, $expiration = null) { - return $this->cacheHandler->addCache($key, $value, $expiration); + return $this->cacheHandler->addCache($name, $value, $expiration); } /** @@ -670,15 +680,15 @@ } /** - * Sets value to database cache + * Sets value to database cache. * - * @param string $name - * @param mixed $value - * @param int|bool $expiration + * @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 void - * @access public */ - public function setDBCache($name, $value, $expiration = false) + public function setDBCache($name, $value, $expiration = null) { $this->cacheHandler->storeStatistics($name, 'WU'); @@ -687,18 +697,21 @@ } /** - * Sets value to database cache + * Sets value to database cache. * - * @param string $name - * @param mixed $value - * @param int|bool $expiration - * @param string $insert_type - * @return bool - * @access protected + * @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). + * @param string $insert_type Insert type. + * + * @return boolean */ - protected function _setDBCache($name, $value, $expiration = false, $insert_type = 'REPLACE') + protected function _setDBCache($name, $value, $expiration = null, $insert_type = 'REPLACE') { - if ( (int)$expiration <= 0 ) { + if ( $expiration === null ) { + $expiration = $this->maxCacheDuration; + } + elseif ( (int)$expiration <= 0 ) { $expiration = -1; } Index: branches/5.2.x/core/units/helpers/category_helper.php =================================================================== diff -u -N -r16559 -r16772 --- branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 16559) +++ branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 16772) @@ -1,6 +1,6 @@ _getChildren($root_category, $languages); if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { - $this->Application->setCache('master:StructureTree', serialize($data)); + $this->Application->setCache('master:StructureTree', serialize($data), 0); } else { - $this->Application->setDBCache('StructureTree', serialize($data)); + $this->Application->setDBCache('StructureTree', serialize($data), 0); } return $data; @@ -274,10 +274,10 @@ } if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { - $data = $this->Application->setCache('master:template_mapping', serialize($mapping)); + $data = $this->Application->setCache('master:template_mapping', serialize($mapping), 0); } else { - $this->Application->setDBCache('template_mapping', serialize($mapping)); + $this->Application->setDBCache('template_mapping', serialize($mapping), 0); } return $mapping; Index: branches/5.2.x/core/units/helpers/menu_helper.php =================================================================== diff -u -N -r16513 -r16772 --- branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 16513) +++ branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 16772) @@ -1,6 +1,6 @@ parentPaths; if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { - $this->Application->setCache('master:cms_menu', serialize($menu)); + $this->Application->setCache('master:cms_menu', serialize($menu), 0); } else { - $this->Application->setDBCache('cms_menu', serialize($menu)); + $this->Application->setDBCache('cms_menu', serialize($menu), 0); } } Index: branches/5.2.x/core/units/helpers/sections_helper.php =================================================================== diff -u -N -r16513 -r16772 --- branches/5.2.x/core/units/helpers/sections_helper.php (.../sections_helper.php) (revision 16513) +++ branches/5.2.x/core/units/helpers/sections_helper.php (.../sections_helper.php) (revision 16772) @@ -1,6 +1,6 @@ Application->HandleEvent(new kEvent('adm:OnAfterBuildTree')); if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) { - $this->Application->setCache('master:sections_parsed', serialize($this->Tree)); + $this->Application->setCache('master:sections_parsed', serialize($this->Tree), 0); } else { - $this->Application->setDBCache('sections_parsed', serialize($this->Tree)); + $this->Application->setDBCache('sections_parsed', serialize($this->Tree), 0); } } @@ -378,4 +378,4 @@ } return $ret; } - } \ No newline at end of file + }