Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/managers/cache_manager.php
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
* Name of database table, where configuration settings are stored | * Name of database table, where configuration settings are stored | ||||
* | * | ||||
* @var string | * @var string | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
protected $settingTableName = ''; | protected $settingTableName = ''; | ||||
/** | /** | ||||
* Maximal cache duration. | |||||
* | |||||
* @var integer | |||||
*/ | |||||
protected $maxCacheDuration; | |||||
/** | |||||
* Set's references to kApplication and DBConnection interface class instances | * Set's references to kApplication and DBConnection interface class instances | ||||
* | * | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
parent::__construct(); | parent::__construct(); | ||||
$this->settingTableName = TABLE_PREFIX . 'SystemSettings'; | $this->settingTableName = TABLE_PREFIX . 'SystemSettings'; | ||||
if ( defined('IS_INSTALL') && IS_INSTALL ) { | if ( defined('IS_INSTALL') && IS_INSTALL ) { | ||||
// table substitution required, so "root" can perform login to upgrade to 5.2.0, where setting table was renamed | // table substitution required, so "root" can perform login to upgrade to 5.2.0, where setting table was renamed | ||||
if ( !$this->Application->TableFound(TABLE_PREFIX . 'SystemSettings') ) { | if ( !$this->Application->TableFound(TABLE_PREFIX . 'SystemSettings') ) { | ||||
$this->settingTableName = TABLE_PREFIX . 'ConfigurationValues'; | $this->settingTableName = TABLE_PREFIX . 'ConfigurationValues'; | ||||
} | } | ||||
} | } | ||||
$this->maxCacheDuration = 60 * 60 * 24 * kUtil::getSystemConfig()->get('MaxCacheDuration', ''); | |||||
} | } | ||||
/** | /** | ||||
* Creates caching manager instance | * Creates caching manager instance | ||||
* | * | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function InitCache() | public function InitCache() | ||||
{ | { | ||||
$this->cacheHandler = $this->Application->makeClass('kCache'); | $this->cacheHandler = $this->Application->makeClass('kCache', array($this->maxCacheDuration)); | ||||
} | } | ||||
/** | /** | ||||
* Returns cache key, used to cache phrase and configuration variable IDs used on current page | * Returns cache key, used to cache phrase and configuration variable IDs used on current page | ||||
* | * | ||||
* @return string | * @return string | ||||
* @access protected | * @access protected | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 230 Lines • ▼ Show 20 Line(s) | |||||
$this->Application->getToCache(), | $this->Application->getToCache(), | ||||
$aggregator->getToCache(), | $aggregator->getToCache(), | ||||
$this->getToCache() | $this->getToCache() | ||||
); | ); | ||||
$cache_rebuild_by = SERVER_NAME . ' (' . $this->Application->getClientIp() . ') - ' . adodb_date('d/m/Y H:i:s'); | $cache_rebuild_by = SERVER_NAME . ' (' . $this->Application->getClientIp() . ') - ' . adodb_date('d/m/Y H:i:s'); | ||||
if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { | if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { | ||||
$this->Application->setCache('master:configs_parsed', serialize($cache)); | $this->Application->setCache('master:configs_parsed', serialize($cache), 0); | ||||
$this->Application->setCache('master:last_cache_rebuild', $cache_rebuild_by); | $this->Application->setCache('master:last_cache_rebuild', $cache_rebuild_by, 0); | ||||
} | } | ||||
else { | else { | ||||
$this->Application->setDBCache('configs_parsed', serialize($cache)); | $this->Application->setDBCache('configs_parsed', serialize($cache), 0); | ||||
$this->Application->setDBCache('last_cache_rebuild', $cache_rebuild_by); | $this->Application->setDBCache('last_cache_rebuild', $cache_rebuild_by, 0); | ||||
} | } | ||||
} | } | ||||
public function delayUnitProcessing($method, $params) | public function delayUnitProcessing($method, $params) | ||||
{ | { | ||||
if ($this->Application->InitDone) { | if ($this->Application->InitDone) { | ||||
// init already done -> call immediately (happens during installation) | // init already done -> call immediately (happens during installation) | ||||
$function = Array (&$this->Application, $method); | $function = Array (&$this->Application, $method); | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | |||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function getCache($key, $store_locally = true, $max_rebuild_seconds = 0) | public function getCache($key, $store_locally = true, $max_rebuild_seconds = 0) | ||||
{ | { | ||||
return $this->cacheHandler->getCache($key, $store_locally, $max_rebuild_seconds); | return $this->cacheHandler->getCache($key, $store_locally, $max_rebuild_seconds); | ||||
} | } | ||||
/** | /** | ||||
* 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 string $name Key name to add to cache. | ||||
* @param mixed $value value of cached record | * @param mixed $value Value of cached record. | ||||
* @param int $expiration when value expires (0 - doesn't expire) | * @param integer|null $expiration When value expires (0 - doesn't expire). | ||||
* @return bool | * | ||||
* @access public | * @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) | * Stores new $value in cache with $key name (only if not there already) | ||||
* | * | ||||
* @param int $key key name to add to cache | * @param string $name Key name to add to cache. | ||||
* @param mixed $value value of cached record | * @param mixed $value Value of cached record. | ||||
* @param int $expiration when value expires (0 - doesn't expire) | * @param integer|null $expiration When value expires (0 - doesn't expire). | ||||
* @return bool | * | ||||
* @access public | * @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); | ||||
} | } | ||||
/** | /** | ||||
* Sets rebuilding mode for given cache | * Sets rebuilding mode for given cache | ||||
* | * | ||||
* @param string $name | * @param string $name | ||||
* @param int $mode | * @param int $mode | ||||
* @param int $max_rebuilding_time | * @param int $max_rebuilding_time | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | |||||
$res[$name] = $cached_data[$name]['Data']; | $res[$name] = $cached_data[$name]['Data']; | ||||
} | } | ||||
return count($res) == 1 ? array_pop($res) : $res; | return count($res) == 1 ? array_pop($res) : $res; | ||||
} | } | ||||
/** | /** | ||||
* 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 | * @return void | ||||
* @access public | |||||
*/ | */ | ||||
public function setDBCache($name, $value, $expiration = false) | public function setDBCache($name, $value, $expiration = null) | ||||
{ | { | ||||
$this->cacheHandler->storeStatistics($name, 'WU'); | $this->cacheHandler->storeStatistics($name, 'WU'); | ||||
$this->deleteDBCache($name . '_rebuilding'); | $this->deleteDBCache($name . '_rebuilding'); | ||||
$this->_setDBCache($name, $value, $expiration); | $this->_setDBCache($name, $value, $expiration); | ||||
} | } | ||||
/** | /** | ||||
* Sets value to database cache | * Sets value to database cache. | ||||
* | * | ||||
* @param string $name | * @param string $name Key name to add to cache. | ||||
* @param mixed $value | * @param mixed $value Value of cached record. | ||||
* @param int|bool $expiration | * @param integer|null $expiration When value expires (0 - doesn't expire). | ||||
* @param string $insert_type | * @param string $insert_type Insert type. | ||||
* @return bool | * | ||||
* @access protected | * @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; | $expiration = -1; | ||||
} | } | ||||
$fields_hash = Array ( | $fields_hash = Array ( | ||||
'VarName' => $name, | 'VarName' => $name, | ||||
'Data' => &$value, | 'Data' => &$value, | ||||
'Cached' => adodb_mktime(), | 'Cached' => adodb_mktime(), | ||||
'LifeTime' => (int)$expiration, | 'LifeTime' => (int)$expiration, | ||||
▲ Show 20 Lines • Show All 161 Lines • Show Last 20 Lines |