Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1102533
D443.id1136.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
Tue, Aug 19, 4:27 AM
Size
16 KB
Mime Type
text/x-diff
Expires
Wed, Aug 20, 4:27 AM (14 h, 13 m)
Engine
blob
Format
Raw Data
Handle
714218
Attached To
D443: INP-1838 - Set expiration limit for life-time cached keys
D443.id1136.diff
View Options
Index: core/install/step_templates/sys_config.tpl
===================================================================
--- core/install/step_templates/sys_config.tpl
+++ 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: core/kernel/application.php
===================================================================
--- core/kernel/application.php
+++ core/kernel/application.php
@@ -863,17 +863,17 @@
}
/**
- * 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 integer $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);
}
/**
@@ -941,15 +941,15 @@
}
/**
- * Sets value to database cache
+ * Sets value to database cache.
+ *
+ * @param integer $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: core/kernel/managers/cache_manager.php
===================================================================
--- core/kernel/managers/cache_manager.php
+++ core/kernel/managers/cache_manager.php
@@ -73,6 +73,13 @@
protected $settingTableName = '';
/**
+ * Default expiration.
+ *
+ * @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,17 +520,17 @@
}
/**
- * 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 integer $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);
}
/**
@@ -670,15 +680,15 @@
}
/**
- * Sets value to database cache
+ * Sets value to database cache.
+ *
+ * @param integer $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,19 +697,19 @@
}
/**
- * 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 integer $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 ) {
- $expiration = -1;
+ if ( $expiration === null ) {
+ $expiration = $this->maxCacheDuration;
}
$fields_hash = Array (
Index: core/kernel/nparser/nparser.php
===================================================================
--- core/kernel/nparser/nparser.php
+++ 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: core/kernel/utility/cache.php
===================================================================
--- core/kernel/utility/cache.php
+++ core/kernel/utility/cache.php
@@ -91,14 +91,22 @@
var $siteKeyValue = null;
/**
+ * Maximum cache duration.
+ *
+ * @var integer
+ */
+ protected $maxDuration;
+
+ /**
* Creates cache manager
*
- * @access public
+ * @param integer $max_duration Maximum duration.
*/
- public function __construct()
+ public function __construct($max_duration)
{
parent::__construct();
+ $this->maxDuration = $max_duration;
$this->siteKeyName = 'site_serial:' . crc32(SQL_TYPE . '://' . SQL_USER . ':' . SQL_PASS . '@' . SQL_SERVER . ':' . TABLE_PREFIX . ':' . SQL_DB);
// get cache handler class to use
@@ -145,15 +153,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 integer $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->maxDuration;
+ }
+
// 1. stores current version of serial for given cache key
$this->_setCache($name . '_serials', $this->replaceSerials($name), $expiration);
$this->storeStatistics($name, 'W');
@@ -599,13 +612,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
*/
- 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)
@@ -686,13 +699,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;
}
@@ -783,13 +796,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);
@@ -854,13 +867,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);
}
@@ -933,13 +946,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);
}
@@ -974,4 +987,4 @@
{
return xcache_unset($name);
}
- }
\ No newline at end of file
+ }
Index: core/kernel/utility/system_config.php
===================================================================
--- core/kernel/utility/system_config.php
+++ 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: core/kernel/utility/unit_config_reader.php
===================================================================
--- core/kernel/utility/unit_config_reader.php
+++ 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: core/units/helpers/category_helper.php
===================================================================
--- core/units/helpers/category_helper.php
+++ 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: core/units/helpers/menu_helper.php
===================================================================
--- core/units/helpers/menu_helper.php
+++ 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: core/units/helpers/sections_helper.php
===================================================================
--- core/units/helpers/sections_helper.php
+++ 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: core/units/helpers/site_helper.php
===================================================================
--- core/units/helpers/site_helper.php
+++ 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