Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F727088
D443.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 6, 6:37 AM
Size
24 KB
Mime Type
text/x-diff
Expires
Tue, Jan 7, 6:37 AM (3 d, 1 h ago)
Engine
blob
Format
Raw Data
Handle
537152
Attached To
D443: INP-1838 - Set expiration limit for life-time cached keys
D443.diff
View Options
Index: branches/5.2.x/core/install/install_toolkit.php
===================================================================
--- branches/5.2.x/core/install/install_toolkit.php
+++ branches/5.2.x/core/install/install_toolkit.php
@@ -967,7 +967,8 @@
$current = $this->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/install/step_templates/sys_config.tpl
===================================================================
--- branches/5.2.x/core/install/step_templates/sys_config.tpl
+++ branches/5.2.x/core/install/step_templates/sys_config.tpl
@@ -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/application.php
===================================================================
--- branches/5.2.x/core/kernel/application.php
+++ branches/5.2.x/core/kernel/application.php
@@ -870,31 +870,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->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 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 $name
- * @param mixed $value
- * @param int|bool $expiration
* @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/managers/cache_manager.php
===================================================================
--- branches/5.2.x/core/kernel/managers/cache_manager.php
+++ branches/5.2.x/core/kernel/managers/cache_manager.php
@@ -73,6 +73,13 @@
protected $settingTableName = '';
/**
+ * Maximal cache duration.
+ *
+ * @var integer
+ */
+ protected $maxCacheDuration;
+
+ /**
* Set's references to kApplication and DBConnection interface class instances
*
* @access public
@@ -89,7 +96,10 @@
$this->settingTableName = TABLE_PREFIX . 'ConfigurationValues';
}
}
+
+ $this->maxCacheDuration = 60 * 60 * 24 * kUtil::getSystemConfig()->get('MaxCacheDuration', '');
}
+
/**
* Creates caching manager instance
*
@@ -97,7 +107,7 @@
*/
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 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 $name
- * @param mixed $value
- * @param int|bool $expiration
* @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/kernel/nparser/nparser.php
===================================================================
--- branches/5.2.x/core/kernel/nparser/nparser.php
+++ branches/5.2.x/core/kernel/nparser/nparser.php
@@ -970,12 +970,17 @@
return $ret;
}
- function setCache($name, $value, $expiration = 0)
+ function setCache($name, $value, $expiration = null)
{
if (!$this->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/cache.php
===================================================================
--- branches/5.2.x/core/kernel/utility/cache.php
+++ branches/5.2.x/core/kernel/utility/cache.php
@@ -91,14 +91,29 @@
var $siteKeyValue = null;
/**
+ * Cache prefix.
+ *
+ * @var string
+ */
+ protected $cachePrefix = '';
+
+ /**
+ * Maximum cache duration.
+ *
+ * @var integer
+ */
+ protected $maxCacheDuration;
+
+ /**
* Creates cache manager
*
- * @access public
+ * @param integer $max_cache_duration Maximum cache duration.
*/
- public function __construct()
+ public function __construct($max_cache_duration)
{
parent::__construct();
+ $this->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,13 +712,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)
{
return true;
}
@@ -700,13 +726,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)
{
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,14 +918,13 @@
/**
* 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);
}
@@ -907,14 +932,13 @@
/**
* 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,13 +988,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)
{
return apc_store($name, $value, $expiration);
}
@@ -978,13 +1002,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)
{
return apc_add($name, $value, $expiration);
}
@@ -1043,13 +1067,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)
{
return xcache_set($name, $value, $expiration);
}
@@ -1057,13 +1081,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)
{
// not atomic operation, like in Memcached and may fail
if ( xcache_isset($name) ) {
Index: branches/5.2.x/core/kernel/utility/system_config.php
===================================================================
--- branches/5.2.x/core/kernel/utility/system_config.php
+++ branches/5.2.x/core/kernel/utility/system_config.php
@@ -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/kernel/utility/unit_config_reader.php
===================================================================
--- branches/5.2.x/core/kernel/utility/unit_config_reader.php
+++ branches/5.2.x/core/kernel/utility/unit_config_reader.php
@@ -224,10 +224,10 @@
if ( $cache ) {
if ( $this->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/category_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/category_helper.php
+++ branches/5.2.x/core/units/helpers/category_helper.php
@@ -209,10 +209,10 @@
$data = $this->_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
===================================================================
--- branches/5.2.x/core/units/helpers/menu_helper.php
+++ branches/5.2.x/core/units/helpers/menu_helper.php
@@ -143,10 +143,10 @@
$menu['parentPaths'] = $this->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
===================================================================
--- branches/5.2.x/core/units/helpers/sections_helper.php
+++ branches/5.2.x/core/units/helpers/sections_helper.php
@@ -203,10 +203,10 @@
$this->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
+ }
Index: branches/5.2.x/core/units/helpers/site_helper.php
===================================================================
--- branches/5.2.x/core/units/helpers/site_helper.php
+++ branches/5.2.x/core/units/helpers/site_helper.php
@@ -85,10 +85,10 @@
$cache = $this->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);
}
}
}
Event Timeline
Log In to Comment