Index: branches/5.2.x/core/units/helpers/category_helper.php
===================================================================
diff -u -N -r14244 -r14560
--- branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 14244)
+++ branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 14560)
@@ -1,6 +1,6 @@
Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $data = $this->Application->getCache('master:StructureTree', false);
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $data = $this->Application->getCache('master:StructureTree', false, CacheSettings::$structureTreeRebuildTime);
}
else {
- $data = $this->Application->getDBCache('StructureTree');
+ $data = $this->Application->getDBCache('StructureTree', CacheSettings::$structureTreeRebuildTime);
}
if ($data) {
@@ -452,6 +452,13 @@
return $data;
}
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:StructureTree', kCache::REBUILD_NOW, CacheSettings::$structureTreeRebuildTime);
+ }
+ else {
+ $this->Application->rebuildDBCache('StructureTree', kCache::REBUILD_NOW, CacheSettings::$structureTreeRebuildTime);
+ }
+
// generate structure tree from scratch
$ml_helper =& $this->Application->recallObject('kMultiLanguageHelper');
/* @var $ml_helper kMultiLanguageHelper */
@@ -472,17 +479,24 @@
function getTemplateMapping()
{
- if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $data = $this->Application->getCache('master:template_mapping', false);
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $data = $this->Application->getCache('master:template_mapping', false, CacheSettings::$templateMappingRebuildTime);
}
else {
- $data = $this->Application->getDBCache('template_mapping');
+ $data = $this->Application->getDBCache('template_mapping', CacheSettings::$templateMappingRebuildTime);
}
- if ($data) {
+ if ( $data ) {
return unserialize($data);
}
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:template_mapping', kCache::REBUILD_NOW, CacheSettings::$templateMappingRebuildTime);
+ }
+ else {
+ $this->Application->rebuildDBCache('template_mapping', kCache::REBUILD_NOW, CacheSettings::$templateMappingRebuildTime);
+ }
+
$sql = 'SELECT
IF(c.`Type` = ' . PAGE_TYPE_TEMPLATE . ', CONCAT(c.Template, ":", c.ThemeId), CONCAT("id:", c.CategoryId)) AS SrcTemplate,
LOWER(
Index: branches/5.2.x/core/units/categories/categories_event_handler.php
===================================================================
diff -u -N -r14474 -r14560
--- branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 14474)
+++ branches/5.2.x/core/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 14560)
@@ -1,6 +1,6 @@
getObject( Array('skip_autoload' => true) );
+ /* @var $temp_object kDBItem */
+
$temp_object->Load($id);
if ($id == 0) {
@@ -925,6 +927,7 @@
$change_events = Array ('OnPreSave', 'OnPreSaveCreated', 'OnUpdate', 'OnSave');
if ($type == 'after' && in_array($event->Name, $change_events)) {
$object =& $event->getObject();
+ /* @var $object kDBItem */
$tmp = $this->Application->RecallVar('priority_changes'.$this->Application->GetVar('m_wid'));
$changes = $tmp ? unserialize($tmp) : array();
@@ -998,8 +1001,13 @@
$to_delete = array();
if ($recycle_bin = $this->Application->ConfigValue('RecycleBinFolder')) {
$rb =& $this->Application->recallObject('c.recycle', null, Array ('skip_autoload' => true));
+ /* @var $rb CategoriesItem */
+
$rb->Load($recycle_bin);
+
$cat =& $event->getObject(Array('skip_autoload' => true));
+ /* @var $cat CategoriesItem */
+
foreach ($ids as $id) {
$cat->Load($id);
if (preg_match('/^'.preg_quote($rb->GetDBField('ParentPath'),'/').'/', $cat->GetDBField('ParentPath'))) {
@@ -1325,6 +1333,7 @@
}
$object =& $event->getObject();
+ /* @var $object kDBItem */
$cache_updater =& $this->Application->makeClass('kPermCacheUpdater', Array (null, $object->GetDBField('ParentPath')));
/* @var $cache_updater kPermCacheUpdater */
@@ -1402,6 +1411,8 @@
}
$object =& $event->getObject( Array('skip_autoload' => true) );
+ /* @var $object CategoriesItem */
+
$ids = $this->StoreSelectedIDs($event);
if ($ids) {
@@ -1652,6 +1663,7 @@
function OnBeforeItemDelete(&$event)
{
$object =& $event->getObject();
+ /* @var $object kDBItem */
if ( $object->GetDBField('Protected') && !$this->Application->isDebugMode() ) {
$event->status = kEvent::erFAIL;
@@ -1851,14 +1863,14 @@
{
// reset cms menu cache (all variables are automatically rebuild, when missing)
if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $this->Application->deleteCache('master:cms_menu');
- $this->Application->deleteCache('master:StructureTree');
- $this->Application->deleteCache('master:template_mapping');
+ $this->Application->rebuildCache('master:cms_menu', kCache::REBUILD_LATER, CacheSettings::$cmsMenuRebuildTime);
+ $this->Application->rebuildCache('master:StructureTree', kCache::REBUILD_LATER, CacheSettings::$structureTreeRebuildTime);
+ $this->Application->rebuildCache('master:template_mapping', kCache::REBUILD_LATER, CacheSettings::$templateMappingRebuildTime);
}
else {
- $this->Application->deleteDBCache('cms_menu');
- $this->Application->deleteDBCache('StructureTree');
- $this->Application->deleteDBCache('template_mapping');
+ $this->Application->rebuildDBCache('cms_menu', kCache::REBUILD_LATER, CacheSettings::$cmsMenuRebuildTime);
+ $this->Application->rebuildDBCache('StructureTree', kCache::REBUILD_LATER, CacheSettings::$structureTreeRebuildTime);
+ $this->Application->rebuildDBCache('template_mapping', kCache::REBUILD_LATER, CacheSettings::$templateMappingRebuildTime);
}
}
@@ -1966,6 +1978,7 @@
}
$object =& $event->getObject();
+ /* @var $object kDBItem */
// remove this category & it's children from dropdown
$sql = 'SELECT '.$object->IDField.'
Index: branches/5.2.x/core/units/helpers/sections_helper.php
===================================================================
diff -u -N -r14244 -r14560
--- branches/5.2.x/core/units/helpers/sections_helper.php (.../sections_helper.php) (revision 14244)
+++ branches/5.2.x/core/units/helpers/sections_helper.php (.../sections_helper.php) (revision 14560)
@@ -1,6 +1,6 @@
Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $data = $this->Application->getCache('master:sections_parsed', false);
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $data = $this->Application->getCache('master:sections_parsed', false, CacheSettings::$sectionsParsedRebuildTime);
}
else {
- $data = $this->Application->getDBCache('sections_parsed');
+ $data = $this->Application->getDBCache('sections_parsed', CacheSettings::$sectionsParsedRebuildTime);
}
- if ($data) {
+ if ( $data ) {
$this->Tree = unserialize($data);
return ;
}
- if (!(defined('IS_INSTALL') && IS_INSTALL)) {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:sections_parsed', kCache::REBUILD_NOW, CacheSettings::$sectionsParsedRebuildTime);
+ }
+ else {
+ $this->Application->rebuildDBCache('sections_parsed', kCache::REBUILD_NOW, CacheSettings::$sectionsParsedRebuildTime);
+ }
+
+ if ( !defined('IS_INSTALL') || !IS_INSTALL ) {
// don't reread all configs during install, because they are reread on every install step
$this->Application->UnitConfigReader->ReReadConfigs();
}
@@ -201,7 +208,7 @@
$this->Application->HandleEvent( new kEvent('adm:OnAfterBuildTree') );
- if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
$this->Application->setCache('master:sections_parsed', serialize($this->Tree));
}
else {
Index: branches/5.2.x/core/kernel/startup.php
===================================================================
diff -u -N -r14428 -r14560
--- branches/5.2.x/core/kernel/startup.php (.../startup.php) (revision 14428)
+++ branches/5.2.x/core/kernel/startup.php (.../startup.php) (revision 14560)
@@ -1,6 +1,6 @@
';
echo 'Please use the installation script to fix the problem.
';
@@ -80,6 +72,14 @@
exit;
}
+ define('APPLICATION_CLASS', isset($vars['ApplicationClass']) ? $vars['ApplicationClass'] : 'kApplication');
+ define('APPLICATION_PATH', isset($vars['ApplicationPath']) ? $vars['ApplicationPath'] : '/core/kernel/application.php');
+
+ if (isset($vars['WriteablePath'])) {
+ define('WRITEABLE', FULL_PATH . $vars['WriteablePath']);
+ define('WRITEBALE_BASE', $vars['WriteablePath']);
+ }
+
define('SQL_TYPE', $vars['DBType']);
define('SQL_SERVER', $vars['DBHost']);
define('SQL_USER', $vars['DBUser']);
@@ -117,6 +117,22 @@
define('CACHING_TYPE_MEMORY', 1);
define('CACHING_TYPE_TEMPORARY', 2);
+ class CacheSettings {
+ static public $unitCacheRebuildTime;
+ static public $structureTreeRebuildTime;
+ static public $cmsMenuRebuildTime;
+ static public $templateMappingRebuildTime;
+ static public $sectionsParsedRebuildTime;
+ static public $domainsParsedRebuildTime;
+ }
+
+ CacheSettings::$unitCacheRebuildTime = isset($vars['UnitCacheRebuildTime']) ? $vars['UnitCacheRebuildTime'] : 10;
+ CacheSettings::$structureTreeRebuildTime = isset($vars['StructureTreeRebuildTime']) ? $vars['StructureTreeRebuildTime'] : 10;
+ CacheSettings::$cmsMenuRebuildTime = isset($vars['CmsMenuRebuildTime']) ? $vars['CmsMenuRebuildTime'] : 10;
+ CacheSettings::$templateMappingRebuildTime = isset($vars['TemplateMappingRebuildTime']) ? $vars['TemplateMappingRebuildTime'] : 5;
+ CacheSettings::$sectionsParsedRebuildTime = isset($vars['SectionsParsedRebuildTime']) ? $vars['SectionsParsedRebuildTime'] : 10;
+ CacheSettings::$domainsParsedRebuildTime = isset($vars['DomainsParsedRebuildTime']) ? $vars['DomainsParsedRebuildTime'] : 2;
+
unset($vars); // just in case someone will be still using it
if (ini_get('safe_mode')) {
Index: branches/5.2.x/core/kernel/managers/cache_manager.php
===================================================================
diff -u -N -r14447 -r14560
--- branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 14447)
+++ branches/5.2.x/core/kernel/managers/cache_manager.php (.../cache_manager.php) (revision 14560)
@@ -1,6 +1,6 @@
Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $data = $this->Application->getCache('master:configs_parsed', false);
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $data = $this->Application->getCache('master:configs_parsed', false, CacheSettings::$unitCacheRebuildTime);
}
else {
- $data = $this->Application->getDBCache('configs_parsed');
+ $data = $this->Application->getDBCache('configs_parsed', CacheSettings::$unitCacheRebuildTime);
}
- if ($data) {
+ if ( $data ) {
$cache = unserialize($data); // 126 KB all modules
unset($data);
@@ -230,6 +230,13 @@
}
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:configs_parsed', kCache::REBUILD_NOW, CacheSettings::$unitCacheRebuildTime);
+ }
+ else {
+ $this->Application->rebuildDBCache('configs_parsed', kCache::REBUILD_NOW, CacheSettings::$unitCacheRebuildTime);
+ }
+
return false;
}
@@ -326,18 +333,18 @@
public function DeleteUnitCache($include_sections = false)
{
if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $this->Application->deleteCache('master:configs_parsed');
+ $this->Application->rebuildCache('master:configs_parsed', kCache::REBUILD_LATER, CacheSettings::$unitCacheRebuildTime);
}
else {
- $this->Application->deleteDBCache('configs_parsed');
+ $this->Application->rebuildDBCache('configs_parsed', kCache::REBUILD_LATER, CacheSettings::$unitCacheRebuildTime);
}
if ($include_sections) {
if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $this->Application->deleteCache('master:sections_parsed');
+ $this->Application->rebuildCache('master:sections_parsed', kCache::REBUILD_LATER, CacheSettings::$sectionsParsedRebuildTime);
}
else {
- $this->Application->deleteDBCache('sections_parsed');
+ $this->Application->rebuildDBCache('sections_parsed', kCache::REBUILD_LATER, CacheSettings::$sectionsParsedRebuildTime);
}
}
}
@@ -447,12 +454,13 @@
*
* @param int $key key name from cache
* @param bool $store_locally store data locally after retrieved
+ * @param int $max_rebuild_seconds
* @return mixed
* @access public
*/
- public function getCache($key, $store_locally = true)
+ public function getCache($key, $store_locally = true, $max_rebuild_seconds = 0)
{
- return $this->cacheHandler->getCache($key, $store_locally);
+ return $this->cacheHandler->getCache($key, $store_locally, $max_rebuild_seconds);
}
/**
@@ -469,6 +477,18 @@
}
/**
+ * Sets rebuilding mode for given cache
+ *
+ * @param string $name
+ * @param int $mode
+ * @param int $max_rebuilding_time
+ */
+ public function rebuildCache($name, $mode = null, $max_rebuilding_time = 0)
+ {
+ $this->cacheHandler->rebuildCache($name, $mode, $max_rebuilding_time);
+ }
+
+ /**
* Deletes key from cache
*
* @param string $key
@@ -493,11 +513,51 @@
* Returns value from database cache
*
* @param string $name key name
+ * @param int $max_rebuild_seconds
* @return mixed
* @access public
*/
- public function getDBCache($name)
+ public function getDBCache($name, $max_rebuild_seconds = 0)
{
+ if ( $this->_getDBCache($name . '_rebuild') ) {
+ // cache rebuild requested -> rebuild now
+ $this->deleteDBCache($name . '_rebuild');
+
+ return false;
+ }
+
+ // no serials in cache key OR cache is outdated
+ $wait_seconds = $max_rebuild_seconds;
+
+ while (true) {
+ $cache = $this->_getDBCache($name);
+ $rebuilding = $this->_getDBCache($name . '_rebuilding');
+
+ if ( ($cache === false) && (!$rebuilding || $wait_seconds == 0) ) {
+ // cache missing and nobody rebuilding it -> rebuild; enough waiting for cache to be ready
+ return false;
+ }
+ elseif ( $cache !== false ) {
+ // cache present -> return it
+ return $cache;
+ }
+
+ $wait_seconds -= kCache::WAIT_STEP;
+ sleep(kCache::WAIT_STEP);
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns value from database cache
+ *
+ * @param string $name key name
+ * @return mixed
+ * @access protected
+ */
+ protected function _getDBCache($name)
+ {
$this->Conn->nextQueryCachable = true;
$sql = 'SELECT Data, Cached, LifeTime
@@ -529,11 +589,25 @@
*
* @param string $name
* @param mixed $value
- * @param int $expiration
+ * @param int|bool $expiration
* @access public
*/
public function setDBCache($name, $value, $expiration = false)
{
+ $this->deleteDBCache($name . '_rebuilding');
+ $this->_setDBCache($name, $value, $expiration);
+ }
+
+ /**
+ * Sets value to database cache
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param int|bool $expiration
+ * @access protected
+ */
+ protected function _setDBCache($name, $value, $expiration = false)
+ {
if ((int)$expiration <= 0) {
$expiration = -1;
}
@@ -550,6 +624,25 @@
}
/**
+ * Sets rebuilding mode for given cache
+ *
+ * @param string $name
+ * @param int $mode
+ * @param int $max_rebuilding_time
+ */
+ public function rebuildDBCache($name, $mode = null, $max_rebuilding_time = 0)
+ {
+ if ( !isset($mode) || $mode == kCache::REBUILD_NOW ) {
+ $this->_setDBCache($name . '_rebuilding', 1, $max_rebuilding_time);
+ $this->deleteDBCache($name . '_rebuild');
+ }
+ elseif ( $mode == kCache::REBUILD_LATER ) {
+ $this->_setDBCache($name . '_rebuild', 1, 0);
+ $this->deleteDBCache($name . '_rebuilding');
+ }
+ }
+
+ /**
* Deletes key from database cache
*
* @param string $name
Index: branches/5.2.x/core/kernel/utility/unit_config_reader.php
===================================================================
diff -u -N -r14428 -r14560
--- branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 14428)
+++ branches/5.2.x/core/kernel/utility/unit_config_reader.php (.../unit_config_reader.php) (revision 14560)
@@ -1,6 +1,6 @@
Application->refreshModuleInfo();
- if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $data = $this->Application->getCache('master:config_files', false);
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $data = $this->Application->getCache('master:config_files', false, CacheSettings::$unitCacheRebuildTime);
}
else {
- $data = $this->Application->getDBCache('config_files');
+ $data = $this->Application->getDBCache('config_files', CacheSettings::$unitCacheRebuildTime);
}
- if ($data) {
+ if ( $data ) {
$this->configFiles = unserialize($data);
if ( !defined('DBG_VALIDATE_CONFIGS') && !DBG_VALIDATE_CONFIGS ) {
shuffle($this->configFiles);
}
}
else {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:config_files', kCache::REBUILD_NOW, CacheSettings::$unitCacheRebuildTime);
+ }
+ else {
+ $this->Application->rebuildDBCache('config_files', kCache::REBUILD_NOW, CacheSettings::$unitCacheRebuildTime);
+ }
+
$this->findConfigFiles(FULL_PATH . DIRECTORY_SEPARATOR . 'core'); // search from core directory
$this->findConfigFiles($folderPath); // search from modules directory
Index: branches/5.2.x/core/kernel/utility/cache.php
===================================================================
diff -u -N -r14244 -r14560
--- branches/5.2.x/core/kernel/utility/cache.php (.../cache.php) (revision 14244)
+++ branches/5.2.x/core/kernel/utility/cache.php (.../cache.php) (revision 14560)
@@ -1,6 +1,6 @@
prepareKeyName($name);
- $this->_localStorage[$name] = $value;
+ // 1. stores current version of serial for given cache key
+ $this->_setCache($name . '_serials', $this->replaceSerials($name), $expiration);
- return $this->_handler->set($name, $value, $expiration);
+ // 2. remove rebuilding mark
+ $this->delete($name . '_rebuilding');
+
+ return $this->_setCache($name, $value, $expiration);
}
/**
+ * Stores value to cache
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param int $expires cache record expiration time in seconds
+ */
+ function _setCache($name, $value, $expiration)
+ {
+ $prepared_name = $this->prepareKeyName($name);
+ $this->_localStorage[$prepared_name] = $value;
+
+ return $this->_handler->set($prepared_name, $value, $expiration);
+ }
+
+ /**
+ * Sets rebuilding mode for given cache
+ *
+ * @param string $name
+ * @param int $mode
+ * @param int $max_rebuilding_time
+ */
+ function rebuildCache($name, $mode = null, $max_rebuilding_time = 0)
+ {
+ if ( !isset($mode) || $mode == self::REBUILD_NOW ) {
+ $this->_setCache($name . '_rebuilding', 1, $max_rebuilding_time);
+ $this->delete($name . '_rebuild');
+ }
+ elseif ( $mode == self::REBUILD_LATER ) {
+ $this->_setCache($name . '_rebuild', 1, 0);
+ $this->delete($name . '_rebuilding');
+ }
+ }
+
+ /**
* Returns value from cache
*
* @param string $name
* @param bool $store_locally store data locally after retrieved
- * @param bool $replace_serials
+ * @param int $max_rebuild_seconds
* @return mixed
*/
- function getCache($name, $store_locally = true, $replace_serials = true)
+ function getCache($name, $store_locally = true, $max_rebuild_seconds = 0)
{
- $name = $this->prepareKeyName($name, $replace_serials);
+ if ( $this->_getCache($name . '_rebuild') ) {
+ // cache rebuild requested -> rebuild now
+ $this->delete($name . '_rebuild');
+ return false;
+ }
+
+ $new_serial = $this->replaceSerials($name);
+ $old_serial = $this->_getCache($name . '_serials');
+
+ if ( $name == $new_serial || $new_serial != $old_serial ) {
+ // no serials in cache key OR cache is outdated
+ $wait_seconds = $max_rebuild_seconds;
+
+ while (true) {
+ $cache = $this->_getCache($name, $store_locally);
+ $rebuilding = $this->_getCache($name . '_rebuilding', false);
+
+ if ( ($cache === false) && (!$rebuilding || $wait_seconds == 0) ) {
+ // cache missing and nobody rebuilding it -> rebuild; enough waiting for cache to be ready
+ return false;
+ }
+ elseif ( $cache !== false ) {
+ // cache present (if other user is rebuilding it, then it's outdated cache) -> return it
+ return $rebuilding || $new_serial == $old_serial ? $cache : false;
+ }
+
+ $wait_seconds -= self::WAIT_STEP;
+ sleep(self::WAIT_STEP);
+ }
+
+ return $cache;
+ }
+
+ return $this->_getCache($name, $store_locally);
+ }
+
+ /**
+ * Returns value from cache
+ *
+ * @param string $name
+ * @param bool $store_locally store data locally after retrieved
+ * @return mixed
+ */
+ function _getCache($name, $store_locally = true)
+ {
+ $name = $this->prepareKeyName($name);
+
if ($store_locally) {
- if (array_key_exists($name, $this->_localStorage)) {
- if ($this->displayCacheStatistics) {
+ if ( array_key_exists($name, $this->_localStorage) ) {
+ if ( $this->displayCacheStatistics ) {
$this->setStatistics($name, $this->_localStorage[$name]);
}
@@ -172,7 +273,7 @@
$res = $this->_handler->get($name);
- if ($replace_serials && $this->debugCache) {
+ if ($this->debugCache) {
// don't display subsequent serial cache retrievals (ones, that are part of keys)
if (is_array($res)) {
$this->Application->Debugger->appendHTML('Restoring key "' . $name . '". Type: ' . gettype($res) . '.');
@@ -188,10 +289,10 @@
}
}
- if ($store_locally && ($res !== false)) {
+ if ( $store_locally && ($res !== false) ) {
$this->_localStorage[$name] = $res;
- if ($this->displayCacheStatistics) {
+ if ( $this->displayCacheStatistics ) {
$this->setStatistics($name, $res);
}
}
@@ -232,27 +333,37 @@
* Replaces serials and adds unique site prefix to cache variable name
*
* @param string $name
- * @param bool $replace_serials
* @return string
*/
- function prepareKeyName($name, $replace_serials = true)
+ protected function prepareKeyName($name)
{
- // replace serials in key name
- if ($replace_serials && preg_match_all('/\[%(.*?)%\]/', $name, $regs)) {
+ if ( $this->cachingType == CACHING_TYPE_TEMPORARY ) {
+ return $name;
+ }
+
+ // add site-wide prefix to key
+ return $this->_cachePrefix() . $name;
+ }
+
+ /**
+ * Replaces serials within given string
+ *
+ * @param string $value
+ * @return string
+ * @access protected
+ */
+ protected function replaceSerials($value)
+ {
+ if ( preg_match_all('/\[%(.*?)%\]/', $value, $regs) ) {
// [%LangSerial%] - prefix-wide serial in case of any change in "lang" prefix
// [%LangIDSerial:5%] - one id-wide serial in case of data, associated with given id was changed
// [%CiIDSerial:ItemResourceId:5%] - foreign key-based serial in case of data, associated with given foreign key was changed
foreach ($regs[1] as $serial_name) {
- $name = str_replace('[%' . $serial_name . '%]', '[' . $serial_name . '=' . $this->getCache($serial_name, true, false) . ']', $name);
+ $value = str_replace('[%' . $serial_name . '%]', '[' . $serial_name . '=' . $this->_getCache($serial_name, true) . ']', $value);
}
}
- if ($this->cachingType == CACHING_TYPE_TEMPORARY) {
- return $name;
- }
-
- // add site-wide prefix to key
- return $this->_cachePrefix() . $name;
+ return $value;
}
/**
Index: branches/5.2.x/core/kernel/application.php
===================================================================
diff -u -N -r14428 -r14560
--- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14428)
+++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 14560)
@@ -1,6 +1,6 @@
cacheManager->getCache($key, $store_locally);
+ return $this->cacheManager->getCache($key, $store_locally, $max_rebuild_seconds);
}
/**
@@ -796,6 +797,18 @@
}
/**
+ * Sets rebuilding mode for given cache
+ *
+ * @param string $name
+ * @param int $mode
+ * @param int $max_rebuilding_time
+ */
+ public function rebuildCache($name, $mode = null, $max_rebuilding_time = 0)
+ {
+ $this->cacheManager->rebuildCache($name, $mode, $max_rebuilding_time);
+ }
+
+ /**
* Deletes key from cache
*
* @param string $key
@@ -820,20 +833,21 @@
* Returns value from database cache
*
* @param string $name key name
+ * @param int $max_rebuild_seconds
* @return mixed
* @access public
*/
- public function getDBCache($name)
+ public function getDBCache($name, $max_rebuild_seconds = 0)
{
- return $this->cacheManager->getDBCache($name);
+ return $this->cacheManager->getDBCache($name, $max_rebuild_seconds);
}
/**
* Sets value to database cache
*
* @param string $name
* @param mixed $value
- * @param int $expiration
+ * @param int|bool $expiration
* @access public
*/
public function setDBCache($name, $value, $expiration = false)
@@ -842,6 +856,18 @@
}
/**
+ * Sets rebuilding mode for given cache
+ *
+ * @param string $name
+ * @param int $mode
+ * @param int $max_rebuilding_time
+ */
+ public function rebuildDBCache($name, $mode = null, $max_rebuilding_time = 0)
+ {
+ $this->cacheManager->rebuildDBCache($name, $mode, $max_rebuilding_time);
+ }
+
+ /**
* Deletes key from database cache
*
* @param string $name
Index: branches/5.2.x/core/units/helpers/site_helper.php
===================================================================
diff -u -N -r14244 -r14560
--- branches/5.2.x/core/units/helpers/site_helper.php (.../site_helper.php) (revision 14244)
+++ branches/5.2.x/core/units/helpers/site_helper.php (.../site_helper.php) (revision 14560)
@@ -1,6 +1,6 @@
Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $cache = $this->Application->getCache('master:domains_parsed', false);
+ if ( !isset($cache) ) {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $cache = $this->Application->getCache('master:domains_parsed', false, CacheSettings::$domainsParsedRebuildTime);
}
else {
- $cache = $this->Application->getDBCache('domains_parsed');
+ $cache = $this->Application->getDBCache('domains_parsed', CacheSettings::$domainsParsedRebuildTime);
}
if ($cache) {
$cache = unserialize($cache);
}
else {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:domains_parsed', kCache::REBUILD_NOW, CacheSettings::$domainsParsedRebuildTime);
+ }
+ else {
+ $this->Application->rebuildDBCache('domains_parsed', kCache::REBUILD_NOW, CacheSettings::$domainsParsedRebuildTime);
+ }
+
$sql = 'SELECT *
FROM ' . TABLE_PREFIX . 'SiteDomains
ORDER BY Priority DESC';
Index: branches/5.2.x/core/units/site_domains/site_domain_eh.php
===================================================================
diff -u -N -r14244 -r14560
--- branches/5.2.x/core/units/site_domains/site_domain_eh.php (.../site_domain_eh.php) (revision 14244)
+++ branches/5.2.x/core/units/site_domains/site_domain_eh.php (.../site_domain_eh.php) (revision 14560)
@@ -1,6 +1,6 @@
Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $this->Application->deleteCache('master:domains_parsed');
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:domains_parsed', kCache::REBUILD_LATER, CacheSettings::$domainsParsedRebuildTime);
}
else {
- $this->Application->deleteDBCache('domains_parsed');
+ $this->Application->rebuildDBCache('domains_parsed', kCache::REBUILD_LATER, CacheSettings::$domainsParsedRebuildTime);
}
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'CachedUrls';
Index: branches/5.2.x/core/units/admin/admin_events_handler.php
===================================================================
diff -u -N -r14244 -r14560
--- branches/5.2.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 14244)
+++ branches/5.2.x/core/units/admin/admin_events_handler.php (.../admin_events_handler.php) (revision 14560)
@@ -1,6 +1,6 @@
Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $this->Application->deleteCache('master:sections_parsed');
+ $this->Application->rebuildCache('master:sections_parsed', kCache::REBUILD_LATER, CacheSettings::$sectionsParsedRebuildTime);
}
else {
- $this->Application->deleteDBCache('sections_parsed');
+ $this->Application->rebuildDBCache('sections_parsed', kCache::REBUILD_LATER, CacheSettings::$sectionsParsedRebuildTime);
}
$event->SetRedirectParam('refresh_tree', 1);
@@ -121,10 +121,10 @@
}
if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $this->Application->deleteCache('master:config_files');
+ $this->Application->rebuildCache('master:config_files', kCache::REBUILD_LATER, CacheSettings::$unitCacheRebuildTime);
}
else {
- $this->Application->deleteDBCache('config_files');
+ $this->Application->rebuildDBCache('config_files', kCache::REBUILD_LATER, CacheSettings::$unitCacheRebuildTime);
}
$this->OnResetParsedData($event);
Index: branches/5.2.x/core/units/helpers/menu_helper.php
===================================================================
diff -u -N -r14244 -r14560
--- branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 14244)
+++ branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 14560)
@@ -1,6 +1,6 @@
Menu) {
- if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) {
- $menu = $this->Application->getCache('master:cms_menu', false);
+ if ( !$this->Menu ) {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $menu = $this->Application->getCache('master:cms_menu', false, CacheSettings::$cmsMenuRebuildTime);
}
else {
- $menu = $this->Application->getDBCache('cms_menu');
+ $menu = $this->Application->getDBCache('cms_menu', CacheSettings::$cmsMenuRebuildTime);
}
if ($menu) {
$menu = unserialize($menu);
$this->parentPaths = $menu['parentPaths'];
}
else {
+ if ( $this->Application->isCachingType(CACHING_TYPE_MEMORY) ) {
+ $this->Application->rebuildCache('master:cms_menu', kCache::REBUILD_NOW, CacheSettings::$cmsMenuRebuildTime);
+ }
+ else {
+ $this->Application->rebuildDBCache('cms_menu', kCache::REBUILD_NOW, CacheSettings::$cmsMenuRebuildTime);
+ }
+
$menu = $this->_altBuildMenuStructure(Array ('CategoryId' => $root_cat, 'ParentPath' => $root_path));
$menu['parentPaths'] = $this->parentPaths;