mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 18:51:41 +09:00
commit
2d833e5668
51 changed files with 2770 additions and 1887 deletions
154
classes/cache/CacheApc.class.php
vendored
154
classes/cache/CacheApc.class.php
vendored
|
|
@ -1,154 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Cache class for APC
|
||||
*
|
||||
* @author NAVER (developer@xpressengine.com)
|
||||
* */
|
||||
class CacheApc extends CacheBase
|
||||
{
|
||||
public static $isSupport = false;
|
||||
|
||||
/**
|
||||
* Get instance of CacheApc
|
||||
*
|
||||
* @param void $opt Not used
|
||||
* @return CacheApc instance of CacheApc
|
||||
*/
|
||||
function getInstance($opt = null)
|
||||
{
|
||||
if(!$GLOBALS['__CacheApc__'])
|
||||
{
|
||||
$GLOBALS['__CacheApc__'] = new CacheApc();
|
||||
}
|
||||
return $GLOBALS['__CacheApc__'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport()
|
||||
{
|
||||
return self::$isSupport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache a variable in the data store
|
||||
*
|
||||
* @param string $key Store the variable using this name. $key are cache-unique, so storing a second value with the same $key will overwrite the original value.
|
||||
* @param mixed $buff The variable to store
|
||||
* @param int $valid_time Time To Live; store $buff in the cache for ttl seconds.
|
||||
* After the ttl has passed., the stored variable will be expunged from the cache (on the next request).
|
||||
* If no ttl is supplied, use the default valid time CacheApc::valid_time.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function put($key, $buff, $valid_time = 0)
|
||||
{
|
||||
if($valid_time == 0)
|
||||
{
|
||||
$valid_time = $this->valid_time;
|
||||
}
|
||||
|
||||
return apc_store(md5(_XE_PATH_ . $key), array($_SERVER['REQUEST_TIME'], $buff), $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
if(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->delete($key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a stored variable from the cache
|
||||
*
|
||||
* @param string $key The $key used to store the value.
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
if(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->delete($key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $obj[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache
|
||||
*
|
||||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
return apc_delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all existing variables at the cache
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate()
|
||||
{
|
||||
return apc_clear_cache('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* @DEPRECATED
|
||||
*/
|
||||
function _delete($key)
|
||||
{
|
||||
return $this->delete($key);
|
||||
}
|
||||
}
|
||||
|
||||
CacheApc::$isSupport = function_exists('apc_add');
|
||||
|
||||
/* End of file CacheApc.class.php */
|
||||
/* Location: ./classes/cache/CacheApc.class.php */
|
||||
171
classes/cache/CacheFile.class.php
vendored
171
classes/cache/CacheFile.class.php
vendored
|
|
@ -1,171 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Cache class for file
|
||||
*
|
||||
* Filedisk Cache Handler
|
||||
*
|
||||
* @author NAVER (developers@xpressengine.com)
|
||||
*/
|
||||
class CacheFile extends CacheBase
|
||||
{
|
||||
/**
|
||||
* Path that value to stored
|
||||
* @var string
|
||||
*/
|
||||
var $cache_dir = 'files/cache/store/';
|
||||
|
||||
/**
|
||||
* Get instance of CacheFile
|
||||
*
|
||||
* @return CacheFile instance of CacheFile
|
||||
*/
|
||||
function getInstance()
|
||||
{
|
||||
if(!$GLOBALS['__CacheFile__'])
|
||||
{
|
||||
$GLOBALS['__CacheFile__'] = new CacheFile();
|
||||
}
|
||||
return $GLOBALS['__CacheFile__'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->cache_dir = _XE_PATH_ . $this->cache_dir;
|
||||
FileHandler::makeDir($this->cache_dir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cache file name by key
|
||||
*
|
||||
* @param string $key The key that will be associated with the item.
|
||||
* @return string Returns cache file path
|
||||
*/
|
||||
function getCacheFileName($key)
|
||||
{
|
||||
return $this->cache_dir . str_replace(':', DIRECTORY_SEPARATOR, $key) . '.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
function isSupport()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache a variable in the data store
|
||||
*
|
||||
* @param string $key Store the variable using this name.
|
||||
* @param mixed $obj The variable to store
|
||||
* @param int $valid_time Not used
|
||||
* @return void
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
$content = array();
|
||||
$content[] = '<?php';
|
||||
$content[] = 'if(!defined(\'__XE__\')) { exit(); }';
|
||||
$content[] = 'return \'' . addslashes(serialize($obj)) . '\';';
|
||||
FileHandler::writeFile($cache_file, implode(PHP_EOL, $content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
|
||||
if(file_exists($cache_file))
|
||||
{
|
||||
if($modified_time > 0 && filemtime($cache_file) < $modified_time)
|
||||
{
|
||||
FileHandler::removeFile($cache_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a stored variable from the cache
|
||||
*
|
||||
* @param string $key The $key used to store the value.
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
if(!$cache_file = FileHandler::exists($this->getCacheFileName($key)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && filemtime($cache_file) < $modified_time)
|
||||
{
|
||||
FileHandler::removeFile($cache_file);
|
||||
return false;
|
||||
}
|
||||
|
||||
$content = include($cache_file);
|
||||
|
||||
return unserialize(stripslashes($content));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache(private)
|
||||
*
|
||||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($_key);
|
||||
FileHandler::removeFile($cache_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache
|
||||
*
|
||||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key)
|
||||
{
|
||||
$this->_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all existing variables at the cache
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate()
|
||||
{
|
||||
FileHandler::removeFilesInDir($this->cache_dir);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheFile.class.php */
|
||||
/* Location: ./classes/cache/CacheFile.class.php */
|
||||
193
classes/cache/CacheHandler.class.php
vendored
193
classes/cache/CacheHandler.class.php
vendored
|
|
@ -9,22 +9,10 @@
|
|||
class CacheHandler extends Handler
|
||||
{
|
||||
/**
|
||||
* Instances are stored here.
|
||||
* Force file cache.
|
||||
*/
|
||||
protected static $_instances = array();
|
||||
protected $_always_use_file = false;
|
||||
|
||||
/**
|
||||
* instance of cache handler
|
||||
* @var CacheBase
|
||||
*/
|
||||
protected $handler = null;
|
||||
|
||||
/**
|
||||
* Version of key group
|
||||
* @var int
|
||||
*/
|
||||
protected $keyGroupVersions = null;
|
||||
|
||||
/**
|
||||
* Get a instance of CacheHandler(for singleton)
|
||||
*
|
||||
|
|
@ -33,14 +21,9 @@ class CacheHandler extends Handler
|
|||
* @param boolean $always_use_file If set true, use a file cache always
|
||||
* @return CacheHandler
|
||||
*/
|
||||
public static function getInstance($target = 'object', $info = null, $always_use_file = false)
|
||||
public static function getInstance($target = null, $info = null, $always_use_file = false)
|
||||
{
|
||||
$key = 'object' . ($always_use_file ? '_file' : '');
|
||||
if (!isset(self::$_instances[$key]))
|
||||
{
|
||||
self::$_instances[$key] = new self($target, $info, $always_use_file);
|
||||
}
|
||||
return self::$_instances[$key];
|
||||
return new self($target, $info, $always_use_file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,48 +37,9 @@ class CacheHandler extends Handler
|
|||
* @param boolean $always_use_file If set true, use a file cache always
|
||||
* @return CacheHandler
|
||||
*/
|
||||
protected function __construct($target, $info = null, $always_use_file = false)
|
||||
protected function __construct($target = null, $info = null, $always_use_file = false)
|
||||
{
|
||||
// Allow using custom cache info for backward compatibility.
|
||||
if (is_object($info) && $info->use_object_cache)
|
||||
{
|
||||
$cache_config = $cache_config_array = $info->use_object_cache;
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache_config = $cache_config_array = config('cache');
|
||||
if (is_array($cache_config) && count($cache_config))
|
||||
{
|
||||
$cache_config = array_first($cache_config);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle various types of cache backend.
|
||||
if (preg_match('/^(apc|memcache|redis|wincache|file)/', strval($cache_config), $matches))
|
||||
{
|
||||
$type = $matches[1];
|
||||
}
|
||||
elseif ($always_use_file)
|
||||
{
|
||||
$type = 'file';
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Create an instance of cache backend.
|
||||
$class = 'Cache' . ucfirst($type);
|
||||
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
|
||||
$this->handler = $class::getInstance($cache_config_array);
|
||||
|
||||
// Initialize key group versions.
|
||||
$this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
|
||||
if(!$this->keyGroupVersions)
|
||||
{
|
||||
$this->keyGroupVersions = array();
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
$this->_always_use_file = $always_use_file;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -103,19 +47,9 @@ class CacheHandler extends Handler
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSupport($type = null, $cache_config = null)
|
||||
public function isSupport()
|
||||
{
|
||||
if ($type === null)
|
||||
{
|
||||
return ($this->handler && $this->handler->isSupport());
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = 'Cache' . ucfirst(str_replace('memcached', 'memcache', $type));
|
||||
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
|
||||
$handler = $class::getInstance($cache_config, true);
|
||||
return $handler->isSupport();
|
||||
}
|
||||
return $this->_always_use_file || (Rhymix\Framework\Cache::getDriverName() !== 'dummy');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,7 +60,7 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function getCacheKey($key)
|
||||
{
|
||||
return RX_VERSION . ':' . str_replace('/', ':', $key);
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -139,8 +73,8 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function get($key, $modified_time = 0)
|
||||
{
|
||||
if (!$key) return false;
|
||||
return $this->handler ? $this->handler->get($this->getCacheKey($key), $modified_time) : false;
|
||||
$value = Rhymix\Framework\Cache::get($key);
|
||||
return $value === null ? false : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -155,8 +89,7 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function put($key, $obj, $valid_time = 0)
|
||||
{
|
||||
if (!$key) return false;
|
||||
return $this->handler ? $this->handler->put($this->getCacheKey($key), $obj, $valid_time) : false;
|
||||
return Rhymix\Framework\Cache::set($key, $obj, $valid_time, $this->_always_use_file);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -167,8 +100,7 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
if (!$key) return false;
|
||||
return $this->handler ? $this->handler->delete($this->getCacheKey($key)) : false;
|
||||
return Rhymix\Framework\Cache::delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -181,8 +113,7 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function isValid($key, $modified_time = 0)
|
||||
{
|
||||
if (!$key) return false;
|
||||
return $this->handler ? $this->handler->isValid($this->getCacheKey($key), $modified_time) : false;
|
||||
return Rhymix\Framework\Cache::exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -192,7 +123,7 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function truncate()
|
||||
{
|
||||
return $this->handler ? $this->handler->truncate() : false;
|
||||
return Rhymix\Framework\Cache::clearAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -213,13 +144,7 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function getGroupKey($keyGroupName, $key)
|
||||
{
|
||||
if(!$this->keyGroupVersions[$keyGroupName])
|
||||
{
|
||||
$this->keyGroupVersions[$keyGroupName] = 1;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
|
||||
return 'cache_group_' . $this->keyGroupVersions[$keyGroupName] . ':' . $keyGroupName . ':' . $key;
|
||||
return $keyGroupName . ':' . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -230,93 +155,9 @@ class CacheHandler extends Handler
|
|||
*/
|
||||
public function invalidateGroupKey($keyGroupName)
|
||||
{
|
||||
$this->keyGroupVersions[$keyGroupName]++;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
return Rhymix\Framework\Cache::clearGroup($keyGroupName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base class of Cache
|
||||
*
|
||||
* @author NAVER (developer@xpressengine.com)
|
||||
*/
|
||||
class CacheBase
|
||||
{
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
*/
|
||||
public $valid_time = 36000;
|
||||
|
||||
/**
|
||||
* Get cached data
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
public function get($key, $modified_time = 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put data into cache
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param mixed $obj Value of a variable to store. $value supports all data types except resources, such as file handlers.
|
||||
* @param int $valid_time Time for the variable to live in the cache in seconds.
|
||||
* After the value specified in ttl has passed the stored variable will be deleted from the cache.
|
||||
* If no ttl is supplied, use the default valid time.
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
public function put($key, $obj, $valid_time = 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias of put()
|
||||
*/
|
||||
public function set($key, $obj, $valid_time = 0)
|
||||
{
|
||||
return $this->put($key, $obj, $valid_time = 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
public function isValid($key, $modified_time = 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSupport()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all cache
|
||||
*
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
public function truncate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheHandler.class.php */
|
||||
/* Location: ./classes/cache/CacheHandler.class.php */
|
||||
|
|
|
|||
219
classes/cache/CacheMemcache.class.php
vendored
219
classes/cache/CacheMemcache.class.php
vendored
|
|
@ -1,219 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Cache class for memcache
|
||||
*
|
||||
* @author NAVER (developer@xpressengine.com)
|
||||
*/
|
||||
class CacheMemcache extends CacheBase
|
||||
{
|
||||
/**
|
||||
* Instance of Memcache
|
||||
*/
|
||||
protected static $_instance;
|
||||
protected $_conn;
|
||||
protected $_status;
|
||||
protected $_useExtension;
|
||||
|
||||
/**
|
||||
* Get instance of CacheMemcache
|
||||
*
|
||||
* @param string $url url of memcache
|
||||
* @return CacheMemcache instance of CacheMemcache
|
||||
*/
|
||||
public static function getInstance($url, $force_new_instance = false)
|
||||
{
|
||||
if(!self::$_instance || $force_new_instance)
|
||||
{
|
||||
self::$_instance = new self($url);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* Do not use this directly. You can use getInstance() instead.
|
||||
* @param string $url url of memcache
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct($url)
|
||||
{
|
||||
//$config['url'] = array('memcache://localhost:11211');
|
||||
$config['url'] = is_array($url) ? $url : array($url);
|
||||
if(class_exists('Memcached'))
|
||||
{
|
||||
$this->_conn = new Memcached;
|
||||
$this->_useExtension = 'Memcached';
|
||||
}
|
||||
elseif(class_exists('Memcache'))
|
||||
{
|
||||
$this->_conn = new Memcache;
|
||||
$this->_useExtension = 'Memcache';
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach($config['url'] as $url)
|
||||
{
|
||||
$info = parse_url($url);
|
||||
$this->_conn->addServer($info['host'], $info['port']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
public function isSupport()
|
||||
{
|
||||
if(isset($this->_status))
|
||||
{
|
||||
return $this->_status;
|
||||
}
|
||||
|
||||
if($this->_useExtension === 'Memcached')
|
||||
{
|
||||
return $this->_status = $this->_conn->set('xe', 'xe', 1);
|
||||
}
|
||||
elseif($this->_useExtension === 'Memcache')
|
||||
{
|
||||
return $this->_status = $this->_conn->set('xe', 'xe', MEMCACHE_COMPRESSED, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique key of given key by path of XE
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @return string Return unique key
|
||||
*/
|
||||
protected function getKey($key)
|
||||
{
|
||||
return md5(_XE_PATH_ . $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data at the server
|
||||
*
|
||||
* CacheMemcache::put() stores an item $buff with $key on the memcached server.
|
||||
* Parameter $valid_time is expiration time in seconds. If it's 0, the item never expires
|
||||
* (but memcached server doesn't guarantee this item to be stored all the time, it could be delete from the cache to make place for other items).
|
||||
*
|
||||
* Remember that resource variables (i.e. file and connection descriptors) cannot be stored in the cache,
|
||||
* because they can not be adequately represented in serialized state.
|
||||
*
|
||||
* @param string $key The key that will be associated with the item.
|
||||
* @param mixed $buff The variable to store. Strings and integers are stored as is, other types are stored serialized.
|
||||
* @param int $valid_time Expiration time of the item.
|
||||
* You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
|
||||
* If it's equal to zero, use the default valid time CacheMemcache::valid_time.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
public function put($key, $buff, $valid_time = 0)
|
||||
{
|
||||
if($valid_time == 0)
|
||||
{
|
||||
$valid_time = $this->valid_time;
|
||||
}
|
||||
|
||||
if($this->_useExtension === 'Memcached')
|
||||
{
|
||||
return $this->_conn->set($this->getKey($key), array(time(), $buff), $valid_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->_conn->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
public function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$obj = $this->_conn->get($this->getKey($key));
|
||||
if(!$obj || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->delete($key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve item from the server
|
||||
*
|
||||
* CacheMemcache::get() returns previously stored data if an item with such $key exists on the server at this moment.
|
||||
*
|
||||
* @param string $key The key to fetch
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
public function get($key, $modified_time = 0)
|
||||
{
|
||||
$obj = $this->_conn->get($this->getKey($key));
|
||||
if(!$obj || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->delete($key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $obj[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item from the server
|
||||
*
|
||||
* CacheMemcache::delete() deletes an item with tey $key.
|
||||
*
|
||||
* @param string $key The key associated with the item to delete.
|
||||
* @return void
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return $this->_conn->delete($this->getKey($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all existing items at the server
|
||||
*
|
||||
* CacheMemcache::truncate() immediately invalidates all existing items.
|
||||
* CacheMemcache::truncate() doesn't actually free any resources, it only marks all the items as expired,
|
||||
* so occupied memory will be overwitten by new items.
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
public function truncate()
|
||||
{
|
||||
return $this->_conn->flush();
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheMemcache.class.php */
|
||||
/* Location: ./classes/cache/CacheMemcache.class.php */
|
||||
242
classes/cache/CacheRedis.class.php
vendored
242
classes/cache/CacheRedis.class.php
vendored
|
|
@ -1,242 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Cache class for Redis
|
||||
*
|
||||
* @author NAVER (developer@xpressengine.com)
|
||||
*/
|
||||
class CacheRedis extends CacheBase
|
||||
{
|
||||
/**
|
||||
* Instance of Memcache
|
||||
*/
|
||||
protected static $_instance;
|
||||
protected $_conn;
|
||||
protected $_status;
|
||||
|
||||
/**
|
||||
* Get instance of CacheRedis
|
||||
*
|
||||
* @param string $url url of Redis
|
||||
* @return CacheRedis instance of CacheRedis
|
||||
*/
|
||||
public static function getInstance($url, $force_new_instance = false)
|
||||
{
|
||||
if(!self::$_instance || $force_new_instance)
|
||||
{
|
||||
self::$_instance = new self($url);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* Do not use this directly. You can use getInstance() instead.
|
||||
* @param string $url url of Redis
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct($url)
|
||||
{
|
||||
//$url = 'redis://localhost:6379/1';
|
||||
$url = is_array($url) ? reset($url) : $url;
|
||||
|
||||
if(!class_exists('Redis'))
|
||||
{
|
||||
$this->_status = false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->_conn = new Redis;
|
||||
$info = parse_url($url);
|
||||
$this->_conn->connect($info['host'], $info['port'], 0.15);
|
||||
if(isset($info['user']) || isset($info['pass']))
|
||||
{
|
||||
$this->_conn->auth(isset($info['user']) ? $info['user'] : $info['pass']);
|
||||
}
|
||||
if(isset($info['path']) && $dbnum = intval(substr($info['path'], 1)))
|
||||
{
|
||||
$this->_conn->select($dbnum);
|
||||
}
|
||||
}
|
||||
catch(RedisException $e)
|
||||
{
|
||||
$this->_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
public function isSupport()
|
||||
{
|
||||
if($this->_status !== null)
|
||||
{
|
||||
return $this->_status;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return $this->_conn->setex('xe', 1, 'xe');
|
||||
}
|
||||
catch(RedisException $e)
|
||||
{
|
||||
return $this->_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique key of given key by path of XE
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @return string Return unique key
|
||||
*/
|
||||
protected function getKey($key)
|
||||
{
|
||||
static $prefix = null;
|
||||
if($prefix === null)
|
||||
{
|
||||
$prefix = substr(sha1(_XE_PATH_), 0, 12) . ':';
|
||||
}
|
||||
return $prefix . $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data at the server
|
||||
*
|
||||
* CacheRedis::put() stores an item $buff with $key on the Redis server.
|
||||
* Parameter $valid_time is expiration time in seconds. If it's 0, the item never expires
|
||||
* (but Redis server doesn't guarantee this item to be stored all the time, it could be delete from the cache to make place for other items).
|
||||
*
|
||||
* Remember that resource variables (i.e. file and connection descriptors) cannot be stored in the cache,
|
||||
* because they can not be adequately represented in serialized state.
|
||||
*
|
||||
* @param string $key The key that will be associated with the item.
|
||||
* @param mixed $buff The variable to store. Strings and integers are stored as is, other types are stored serialized.
|
||||
* @param int $valid_time Expiration time of the item.
|
||||
* You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days).
|
||||
* If it's equal to zero, use the default valid time CacheRedis::valid_time.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
public function put($key, $buff, $valid_time = 0)
|
||||
{
|
||||
if($valid_time > 60 * 60 * 24 * 30)
|
||||
{
|
||||
$valid_time = $valid_time - time();
|
||||
}
|
||||
if($valid_time <= 0)
|
||||
{
|
||||
$valid_time = $this->valid_time;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return $this->_conn->setex($this->getKey($key), $valid_time, serialize(array($_SERVER['REQUEST_TIME'], $buff)));
|
||||
}
|
||||
catch(RedisException $e)
|
||||
{
|
||||
return $this->_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
public function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$obj = $this->_conn->get($this->getKey($key));
|
||||
$obj = $obj ? unserialize($obj) : false;
|
||||
if(!$obj || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_conn->del($this->getKey($key));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve item from the server
|
||||
*
|
||||
* CacheRedis::get() returns previously stored data if an item with such $key exists on the server at this moment.
|
||||
*
|
||||
* @param string $key The key to fetch
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
public function get($key, $modified_time = 0)
|
||||
{
|
||||
$obj = $this->_conn->get($this->getKey($key));
|
||||
$obj = $obj ? unserialize($obj) : false;
|
||||
if(!$obj || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_conn->del($this->getKey($key));
|
||||
return false;
|
||||
}
|
||||
|
||||
return $obj[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete item from the server
|
||||
*
|
||||
* CacheRedis::delete() deletes an item with tey $key.
|
||||
*
|
||||
* @param string $key The key associated with the item to delete.
|
||||
* @return void
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->del($this->getKey($key));
|
||||
}
|
||||
catch(RedisException $e)
|
||||
{
|
||||
return $this->_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush all existing items at the server
|
||||
*
|
||||
* CacheRedis::truncate() immediately invalidates all existing items.
|
||||
* If using multiple databases, items in other databases are not affected.
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
public function truncate()
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->flushDB();
|
||||
}
|
||||
catch(RedisException $e)
|
||||
{
|
||||
return $this->_status = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheRedis.class.php */
|
||||
/* Location: ./classes/cache/CacheRedis.class.php */
|
||||
158
classes/cache/CacheWincache.class.php
vendored
158
classes/cache/CacheWincache.class.php
vendored
|
|
@ -1,158 +0,0 @@
|
|||
<?php
|
||||
/* Copyright (C) NAVER <http://www.navercorp.com> */
|
||||
|
||||
/**
|
||||
* Cache class for Wincache
|
||||
*
|
||||
* Wincache Handler
|
||||
*
|
||||
* @author Arnia (support@xpressengine.org)
|
||||
*/
|
||||
class CacheWincache extends CacheBase
|
||||
{
|
||||
public static $isSupport = false;
|
||||
|
||||
/**
|
||||
* Get instance of CacheWincache
|
||||
*
|
||||
* @param void $opt Not used
|
||||
* @return CacheWincache instance of CacheWincache
|
||||
*/
|
||||
function getInstance($opt = null)
|
||||
{
|
||||
if(!$GLOBALS['__CacheWincache__'])
|
||||
{
|
||||
$GLOBALS['__CacheWincache__'] = new CacheWincache();
|
||||
}
|
||||
return $GLOBALS['__CacheWincache__'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport()
|
||||
{
|
||||
return self::$isSupport;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a variable in user cache and overwrites a variable if it already exists in the cache
|
||||
*
|
||||
* @param string $key Store the variable using this $key value.
|
||||
* If a variable with same $key is already present the function will overwrite the previous value with the new one.
|
||||
* @param mixed $buff Value of a variable to store. $value supports all data types except resources, such as file handlers.
|
||||
* @param int $valid_time Time for the variable to live in the cache in seconds.
|
||||
* After the value specified in ttl has passed the stored variable will be deleted from the cache.
|
||||
* If no ttl is supplied, use the default valid time CacheWincache::valid_time.
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function put($key, $buff, $valid_time = 0)
|
||||
{
|
||||
if($valid_time == 0)
|
||||
{
|
||||
$valid_time = $this->valid_time;
|
||||
}
|
||||
return wincache_ucache_set(md5(_XE_PATH_ . $key), array($_SERVER['REQUEST_TIME'], $buff), $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether cache is valid or invalid
|
||||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, the data is invalid.
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$obj = wincache_ucache_get($_key, $success);
|
||||
if(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a variable stored in the user cache
|
||||
*
|
||||
* @param string $key The $key that was used to store the variable in the cache.
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* @return false|mixed Return false on failure or older then modified time. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$obj = wincache_ucache_get($_key, $success);
|
||||
if(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $obj[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache(private)
|
||||
*
|
||||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key)
|
||||
{
|
||||
wincache_ucache_delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete variable from the cache
|
||||
*
|
||||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate all existing variables at the cache
|
||||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate()
|
||||
{
|
||||
return wincache_ucache_clear();
|
||||
}
|
||||
}
|
||||
|
||||
CacheWincache::$isSupport = function_exists('wincache_ucache_set');
|
||||
/* End of file CacheWincache.class.php */
|
||||
/* Location: ./classes/cache/CacheWincache.class.php */
|
||||
|
|
@ -369,7 +369,7 @@ class DB
|
|||
$log['time'] = date('Y-m-d H:i:s');
|
||||
$log['backtrace'] = array();
|
||||
|
||||
if (config('debug.enabled') && config('debug.log_queries'))
|
||||
if (config('debug.enabled') && in_array('queries', config('debug.display_content')))
|
||||
{
|
||||
$bt = defined('DEBUG_BACKTRACE_IGNORE_ARGS') ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) : debug_backtrace();
|
||||
foreach($bt as $no => $call)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ if(file_exists(RX_BASEDIR . 'config/config.user.inc.php'))
|
|||
* Define the list of legacy class names for the autoloader.
|
||||
*/
|
||||
$GLOBALS['RX_AUTOLOAD_FILE_MAP'] = array_change_key_case(array(
|
||||
'CacheBase' => 'classes/cache/CacheHandler.class.php',
|
||||
'CacheHandler' => 'classes/cache/CacheHandler.class.php',
|
||||
'Context' => 'classes/context/Context.class.php',
|
||||
'DB' => 'classes/db/DB.class.php',
|
||||
|
|
@ -202,3 +201,8 @@ Rhymix\Framework\Debug::registerErrorHandlers(error_reporting());
|
|||
*/
|
||||
$internal_timezone = Rhymix\Framework\DateTime::getTimezoneNameByOffset(config('locale.internal_timezone'));
|
||||
date_default_timezone_set($internal_timezone);
|
||||
|
||||
/**
|
||||
* Initialize the cache handler.
|
||||
*/
|
||||
Rhymix\Framework\Cache::init(Rhymix\Framework\Config::get('cache'));
|
||||
|
|
|
|||
352
common/framework/cache.php
Normal file
352
common/framework/cache.php
Normal file
|
|
@ -0,0 +1,352 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework;
|
||||
|
||||
/**
|
||||
* The cache class.
|
||||
*/
|
||||
class Cache
|
||||
{
|
||||
/**
|
||||
* The currently enabled cache driver.
|
||||
*/
|
||||
protected static $_driver = null;
|
||||
protected static $_driver_name = null;
|
||||
|
||||
/**
|
||||
* The cache prefix.
|
||||
*/
|
||||
protected static $_prefix = null;
|
||||
|
||||
/**
|
||||
* The default TTL.
|
||||
*/
|
||||
protected static $_ttl = 86400;
|
||||
|
||||
/**
|
||||
* Cache group versions.
|
||||
*/
|
||||
protected static $_group_versions = array();
|
||||
|
||||
/**
|
||||
* Initialize the cache system.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function init($config)
|
||||
{
|
||||
if (!is_array($config))
|
||||
{
|
||||
$config = array($config);
|
||||
}
|
||||
|
||||
if (isset($config['type']))
|
||||
{
|
||||
$driver_name = $config['type'];
|
||||
$class_name = '\\Rhymix\\Framework\\Drivers\\Cache\\' . $config['type'];
|
||||
if (isset($config['ttl']))
|
||||
{
|
||||
self::$_ttl = intval($config['ttl']);
|
||||
}
|
||||
$config = isset($config['servers']) ? $config['servers'] : array();
|
||||
}
|
||||
elseif (preg_match('/^(apc|dummy|file|memcache|redis|sqlite|wincache|xcache)/', strval(array_first($config)), $matches))
|
||||
{
|
||||
$driver_name = $matches[1] . ($matches[1] === 'memcache' ? 'd' : '');
|
||||
$class_name = '\\Rhymix\\Framework\\Drivers\\Cache\\' . $driver_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
$driver_name = null;
|
||||
$class_name = null;
|
||||
}
|
||||
|
||||
if ($class_name && class_exists($class_name) && $class_name::isSupported())
|
||||
{
|
||||
self::$_driver = $class_name::getInstance($config);
|
||||
self::$_driver_name = strtolower($driver_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_driver = Drivers\Cache\Dummy::getInstance(array());
|
||||
self::$_driver_name = 'dummy';
|
||||
}
|
||||
|
||||
if (self::$_driver->prefix)
|
||||
{
|
||||
self::$_prefix = substr(sha1(\RX_BASEDIR), 0, 10) . ':' . \RX_VERSION . ':';
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_prefix = \RX_VERSION . ':';
|
||||
}
|
||||
|
||||
return self::$_driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of supported cache drivers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getSupportedDrivers()
|
||||
{
|
||||
$result = array();
|
||||
foreach (Storage::readDirectory(__DIR__ . '/drivers/cache', false) as $filename)
|
||||
{
|
||||
$driver_name = substr($filename, 0, -4);
|
||||
$class_name = '\Rhymix\Framework\Drivers\Cache\\' . $driver_name;
|
||||
if ($class_name::isSupported())
|
||||
{
|
||||
$result[] = $driver_name;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the currently enabled cache driver.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function getDriverName()
|
||||
{
|
||||
return self::$_driver_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently enabled cache driver, or a named driver with the given settings.
|
||||
*
|
||||
* @param string $name (optional)
|
||||
* @param array $config (optional)
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getDriverInstance($name = null, array $config = [])
|
||||
{
|
||||
if ($name === null)
|
||||
{
|
||||
return self::$_driver;
|
||||
}
|
||||
else
|
||||
{
|
||||
$class_name = '\\Rhymix\\Framework\\Drivers\\Cache\\' . $name;
|
||||
if (class_exists($class_name) && $class_name::isSupported() && $class_name::validateSettings($config))
|
||||
{
|
||||
return $class_name::getInstance($config);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the automatically generated cache prefix for this installation of Rhymix.
|
||||
*
|
||||
* @return object|null
|
||||
*/
|
||||
public static function getPrefix()
|
||||
{
|
||||
return self::$_prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default TTL.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getDefaultTTL()
|
||||
{
|
||||
return self::$_ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default TTL.
|
||||
*
|
||||
* @param int $ttl
|
||||
* @return void
|
||||
*/
|
||||
public static function setDefaultTTL($ttl)
|
||||
{
|
||||
self::$_ttl = $ttl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($key)
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
return self::$_driver->get(self::getRealKey($key));
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is not given, the default TTL is used.
|
||||
* $force is used to cache essential data when using the default driver.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl (optional)
|
||||
* @param bool $force (optional)
|
||||
* @return bool
|
||||
*/
|
||||
public static function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
$ttl = intval($ttl);
|
||||
if ($ttl >= (3600 * 24 * 30))
|
||||
{
|
||||
$ttl = min(3600 * 24 * 30, max(0, $ttl - time()));
|
||||
}
|
||||
if ($ttl === 0)
|
||||
{
|
||||
$ttl = self::$_ttl;
|
||||
}
|
||||
return self::$_driver->set(self::getRealKey($key), $value, $ttl, $force) ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete($key)
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
return self::$_driver->delete(self::getRealKey($key)) ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($key)
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
return self::$_driver->exists(self::getRealKey($key)) ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a group of keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $group_name
|
||||
* @return bool
|
||||
*/
|
||||
public static function clearGroup($group_name)
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
$success = self::$_driver->incr(self::$_prefix . $group_name . '#version', 1) ? true : false;
|
||||
unset(self::$_group_versions[$group_name]);
|
||||
return $success;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function clearAll()
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
return self::$_driver->clear() ? true : false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group version.
|
||||
*
|
||||
* @param string $group_name
|
||||
* @return int
|
||||
*/
|
||||
public static function getGroupVersion($group_name)
|
||||
{
|
||||
if (isset(self::$_group_versions[$group_name]))
|
||||
{
|
||||
return self::$_group_versions[$group_name];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
return self::$_group_versions[$group_name] = intval(self::$_driver->get(self::$_prefix . $group_name . '#version'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::$_group_versions[$group_name] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the actual key used by Rhymix.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
public static function getRealKey($key)
|
||||
{
|
||||
if (preg_match('/^([^:]+):(.+)$/i', $key, $matches))
|
||||
{
|
||||
$key = $matches[1] . '#' . self::getGroupVersion($matches[1]) . ':' . $matches[2];
|
||||
}
|
||||
|
||||
return self::$_prefix . $key;
|
||||
}
|
||||
}
|
||||
179
common/framework/drivers/cache/apc.php
vendored
Normal file
179
common/framework/drivers/cache/apc.php
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
/**
|
||||
* The APC cache driver.
|
||||
*/
|
||||
class APC implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = true;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (self::$_instance === null)
|
||||
{
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return function_exists('apc_exists');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = apc_fetch($key);
|
||||
return $value === false ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
return apc_store($key, $value, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return apc_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
return apc_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount)
|
||||
{
|
||||
$result = apc_inc($key, $amount);
|
||||
if ($result === false)
|
||||
{
|
||||
apc_store($key, $amount);
|
||||
$result = $amount;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount)
|
||||
{
|
||||
$result = apc_dec($key, $amount);
|
||||
if ($result === false)
|
||||
{
|
||||
apc_store($key, 0 - $amount);
|
||||
$result = 0 - $amount;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
return apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
132
common/framework/drivers/cache/dummy.php
vendored
Normal file
132
common/framework/drivers/cache/dummy.php
vendored
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
/**
|
||||
* The dummy cache driver.
|
||||
*/
|
||||
class Dummy extends File implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = false;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* Dummy data is stored here.
|
||||
*/
|
||||
public $data = array();
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if ($value !== null)
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
elseif (isset($this->data[$key]))
|
||||
{
|
||||
if ($this->data[$key][0] > 0 && $this->data[$key][0] < time())
|
||||
{
|
||||
unset($this->data[$key]);
|
||||
return null;
|
||||
}
|
||||
return $this->data[$key][1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
if ($force)
|
||||
{
|
||||
return parent::set($key, $value, $ttl, $force);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->data[$key] = array($ttl ? (time() + $ttl) : 0, $value);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
if (parent::delete($key))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
elseif (isset($this->data[$key]))
|
||||
{
|
||||
unset($this->data[$key]);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
return parent::exists($key) || isset($this->data[$key]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
parent::clear();
|
||||
$this->data = array();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
206
common/framework/drivers/cache/file.php
vendored
Normal file
206
common/framework/drivers/cache/file.php
vendored
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
use Rhymix\Framework\Storage;
|
||||
|
||||
/**
|
||||
* The file cache driver.
|
||||
*/
|
||||
class File implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = false;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* The cache directory.
|
||||
*/
|
||||
protected $_dir;
|
||||
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct(array $config)
|
||||
{
|
||||
$this->_dir = \RX_BASEDIR . 'files/cache/store';
|
||||
if (!Storage::isDirectory($this->_dir))
|
||||
{
|
||||
Storage::createDirectory($this->_dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (static::$_instance === null)
|
||||
{
|
||||
static::$_instance = new static($config);
|
||||
}
|
||||
return static::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$filename = $this->_getFilename($key);
|
||||
$data = Storage::readPHPData($filename);
|
||||
|
||||
if ($data === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
elseif (!is_array($data) || count($data) < 2 || ($data[0] > 0 && $data[0] < time()))
|
||||
{
|
||||
Storage::delete($filename);
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $data[1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
return Storage::writePHPData($this->_getFilename($key), array($ttl ? (time() + $ttl) : 0, $value), $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return Storage::delete($this->_getFilename($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
return $this->get($key) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount)
|
||||
{
|
||||
$value = intval($this->get($key));
|
||||
$success = $this->set($key, $value + $amount, 0);
|
||||
return $success ? ($value + $amount) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount)
|
||||
{
|
||||
return $this->incr($key, 0 - $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
return Storage::deleteDirectory($this->_dir) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filename to store a key.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function _getFilename($key)
|
||||
{
|
||||
$hash = sha1($key);
|
||||
return $this->_dir . '/' . substr($hash, 0, 2) . '/' . substr($hash, 2, 2) . '/' . $hash . '.php';
|
||||
}
|
||||
}
|
||||
251
common/framework/drivers/cache/memcached.php
vendored
Normal file
251
common/framework/drivers/cache/memcached.php
vendored
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
/**
|
||||
* The Memcached cache driver.
|
||||
*/
|
||||
class Memcached implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = true;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* The Memcached connection is stored here.
|
||||
*/
|
||||
protected $_conn = null;
|
||||
protected $_ext = null;
|
||||
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct(array $config)
|
||||
{
|
||||
if (class_exists('\\Memcached', false))
|
||||
{
|
||||
$this->_conn = new \Memcached;
|
||||
$this->_ext = 'Memcached';
|
||||
}
|
||||
elseif (class_exists('\\Memcache', false))
|
||||
{
|
||||
$this->_conn = new \Memcache;
|
||||
$this->_ext = 'Memcache';
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($config as $url)
|
||||
{
|
||||
$info = parse_url($url);
|
||||
if (isset($info['host']) && isset($info['port']))
|
||||
{
|
||||
$this->_conn->addServer($info['host'], $info['port']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (self::$_instance === null)
|
||||
{
|
||||
self::$_instance = new self($config);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return class_exists('\\Memcached', false) || class_exists('\\Memcache', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config)
|
||||
{
|
||||
if (class_exists('\\Memcached', false))
|
||||
{
|
||||
$conn = new \Memcached;
|
||||
$ext = 'Memcached';
|
||||
}
|
||||
elseif (class_exists('\\Memcache', false))
|
||||
{
|
||||
$conn = new \Memcache;
|
||||
$ext = 'Memcache';
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($config as $url)
|
||||
{
|
||||
$info = parse_url($url);
|
||||
if (isset($info['host']) && isset($info['port']))
|
||||
{
|
||||
$conn->addServer($info['host'], $info['port']);
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 5; $i++)
|
||||
{
|
||||
$key = 'rhymix:test:' . md5($i);
|
||||
$status = ($ext === 'Memcached') ? $conn->set($key, $i, 2) : $conn->set($key, $i, 0, 2);
|
||||
if (!$status) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = $this->_conn->get($key);
|
||||
if ($value === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
if ($this->_ext === 'Memcached')
|
||||
{
|
||||
return $this->_conn->set($key, $value, $ttl);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->_conn->set($key, $value, MEMCACHE_COMPRESSED, $ttl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return $this->_conn->delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
return $this->_conn->get($key) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount)
|
||||
{
|
||||
$result = $this->_conn->increment($key, $amount);
|
||||
if ($result === false)
|
||||
{
|
||||
$this->set($key, $amount);
|
||||
$result = $amount;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount)
|
||||
{
|
||||
$result = $this->_conn->decrement($key, $amount);
|
||||
if ($result === false)
|
||||
{
|
||||
$this->set($key, 0 - $amount);
|
||||
$result = 0 - $amount;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
return $this->_conn->flush();
|
||||
}
|
||||
}
|
||||
282
common/framework/drivers/cache/redis.php
vendored
Normal file
282
common/framework/drivers/cache/redis.php
vendored
Normal file
|
|
@ -0,0 +1,282 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
/**
|
||||
* The Redis cache driver.
|
||||
*/
|
||||
class Redis implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = true;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* The Redis connection is stored here.
|
||||
*/
|
||||
protected $_conn = null;
|
||||
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct(array $config)
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->_conn = new \Redis;
|
||||
foreach ($config as $url)
|
||||
{
|
||||
$info = parse_url($url);
|
||||
if (isset($info['host']) && isset($info['port']))
|
||||
{
|
||||
$this->_conn->connect($info['host'], $info['port'], 0.15);
|
||||
if(isset($info['user']) || isset($info['pass']))
|
||||
{
|
||||
$this->_conn->auth(isset($info['user']) ? $info['user'] : $info['pass']);
|
||||
}
|
||||
if(isset($info['path']) && $dbnum = intval(substr($info['path'], 1)))
|
||||
{
|
||||
$this->_conn->select($dbnum);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->_conn = null;
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
$this->_conn = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (self::$_instance === null)
|
||||
{
|
||||
self::$_instance = new self($config);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return class_exists('\\Redis', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config)
|
||||
{
|
||||
try
|
||||
{
|
||||
$conn = new \Redis;
|
||||
foreach ($config as $url)
|
||||
{
|
||||
$info = parse_url($url);
|
||||
if (isset($info['host']) && isset($info['port']))
|
||||
{
|
||||
$conn->connect($info['host'], $info['port'], 0.15);
|
||||
if(isset($info['user']) || isset($info['pass']))
|
||||
{
|
||||
$conn->auth(isset($info['user']) ? $info['user'] : $info['pass']);
|
||||
}
|
||||
if(isset($info['path']) && $dbnum = intval(substr($info['path'], 1)))
|
||||
{
|
||||
$conn->select($dbnum);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
try
|
||||
{
|
||||
$value = $this->_conn->get($key);
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($value === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = unserialize($value);
|
||||
if ($value === false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->setex($key, $ttl, serialize($value)) ? true : false;
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->del($key) ? true : false;
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->exists($key);
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->incrBy($key, $amount);
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount)
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->decrBy($key, $amount);
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
try
|
||||
{
|
||||
return $this->_conn->flushDB() ? true : false;
|
||||
}
|
||||
catch (\RedisException $e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
266
common/framework/drivers/cache/sqlite.php
vendored
Normal file
266
common/framework/drivers/cache/sqlite.php
vendored
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
use Rhymix\Framework\Storage;
|
||||
|
||||
/**
|
||||
* The SQLite cache driver.
|
||||
*/
|
||||
class SQLite implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = false;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* The database handle and prepared statements are stored here.
|
||||
*/
|
||||
protected $_dbh = null;
|
||||
protected $_ps = array();
|
||||
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
$dir = \RX_BASEDIR . 'files/cache/store';
|
||||
if (!Storage::isDirectory($dir))
|
||||
{
|
||||
Storage::createDirectory($dir);
|
||||
}
|
||||
|
||||
$key = substr(hash_hmac('sha256', $dir, config('crypto.authentication_key')), 0, 32);
|
||||
$filename = "$dir/$key.db";
|
||||
if (Storage::exists($filename))
|
||||
{
|
||||
$this->_connect($filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_connect($filename);
|
||||
for ($i = 0; $i < 32; $i++)
|
||||
{
|
||||
$this->_dbh->exec('CREATE TABLE cache_' . $i . ' (k TEXT PRIMARY KEY, v TEXT, exp INT)');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to an SQLite3 database.
|
||||
*
|
||||
* @param string $filename
|
||||
* @return void
|
||||
*/
|
||||
protected function _connect($filename)
|
||||
{
|
||||
$this->_dbh = new \SQLite3($filename);
|
||||
$this->_dbh->exec('PRAGMA journal_mode = MEMORY');
|
||||
$this->_dbh->exec('PRAGMA synchronous = OFF');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (self::$_instance === null)
|
||||
{
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return class_exists('\\SQLite3', false) && config('crypto.authentication_key') !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$table = 'cache_' . (crc32($key) % 32);
|
||||
$stmt = $this->_dbh->prepare('SELECT v, exp FROM ' . $table . ' WHERE k = :key');
|
||||
$stmt->bindValue(':key', $key, \SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(\SQLITE3_NUM);
|
||||
if ($row)
|
||||
{
|
||||
if ($row[1] == 0 || $row[1] >= time())
|
||||
{
|
||||
return unserialize($row[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->delete($key);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
$table = 'cache_' . (crc32($key) % 32);
|
||||
$stmt = $this->_dbh->prepare('INSERT OR REPLACE INTO ' . $table . ' (k, v, exp) VALUES (:key, :val, :exp)');
|
||||
$stmt->bindValue(':key', $key, \SQLITE3_TEXT);
|
||||
$stmt->bindValue(':val', serialize($value), \SQLITE3_TEXT);
|
||||
$stmt->bindValue(':exp', $ttl ? (time() + $ttl) : 0, \SQLITE3_INTEGER);
|
||||
return $stmt->execute() ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
$table = 'cache_' . (crc32($key) % 32);
|
||||
$stmt = $this->_dbh->prepare('DELETE FROM ' . $table . ' WHERE k = :key');
|
||||
$stmt->bindValue(':key', $key, \SQLITE3_TEXT);
|
||||
return $stmt->execute() ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
$table = 'cache_' . (crc32($key) % 32);
|
||||
$stmt = $this->_dbh->prepare('SELECT 1 FROM ' . $table . ' WHERE k = :key AND (exp = 0 OR exp >= :exp)');
|
||||
$stmt->bindValue(':key', $key, \SQLITE3_TEXT);
|
||||
$stmt->bindValue(':exp', time(), \SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(\SQLITE3_NUM);
|
||||
if ($row)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount)
|
||||
{
|
||||
$current_value = $this->get($key);
|
||||
$new_value = intval($current_value) + $amount;
|
||||
if ($this->set($key, $new_value))
|
||||
{
|
||||
return $new_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount)
|
||||
{
|
||||
return $this->incr($key, 0 - $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
for ($i = 0; $i < 32; $i++)
|
||||
{
|
||||
$this->_dbh->exec('DROP TABLE cache_' . $i);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < 32; $i++)
|
||||
{
|
||||
$this->_dbh->exec('CREATE TABLE cache_' . $i . ' (k TEXT PRIMARY KEY, v TEXT, exp INT)');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
179
common/framework/drivers/cache/wincache.php
vendored
Normal file
179
common/framework/drivers/cache/wincache.php
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
/**
|
||||
* The WinCache cache driver.
|
||||
*/
|
||||
class WinCache implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = true;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (self::$_instance === null)
|
||||
{
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return function_exists('wincache_ucache_get');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = wincache_ucache_get($key, $success);
|
||||
return $success ? $value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
return wincache_ucache_set($key, $value, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return wincache_ucache_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
return wincache_ucache_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount)
|
||||
{
|
||||
$result = wincache_ucache_inc($key, $amount);
|
||||
if ($result === false)
|
||||
{
|
||||
wincache_ucache_set($key, $amount);
|
||||
$result = $amount;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount)
|
||||
{
|
||||
$result = wincache_ucache_dec($key, $amount);
|
||||
if ($result === false)
|
||||
{
|
||||
wincache_ucache_set($key, 0 - $amount);
|
||||
$result = 0 - $amount;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
return wincache_ucache_clear();
|
||||
}
|
||||
}
|
||||
168
common/framework/drivers/cache/xcache.php
vendored
Normal file
168
common/framework/drivers/cache/xcache.php
vendored
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers\Cache;
|
||||
|
||||
/**
|
||||
* The XCache cache driver.
|
||||
*/
|
||||
class XCache implements \Rhymix\Framework\Drivers\CacheInterface
|
||||
{
|
||||
/**
|
||||
* Set this flag to false to disable cache prefixes.
|
||||
*/
|
||||
public $prefix = true;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (self::$_instance === null)
|
||||
{
|
||||
self::$_instance = new self();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported()
|
||||
{
|
||||
return function_exists('xcache_get');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$value = xcache_get($key);
|
||||
return $value === false ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false)
|
||||
{
|
||||
return xcache_set($key, $value, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key)
|
||||
{
|
||||
return xcache_unset($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key)
|
||||
{
|
||||
return xcache_isset($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount)
|
||||
{
|
||||
return xcache_inc($key, $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount)
|
||||
{
|
||||
return xcache_dec($key, $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
xcache_clear_cache(XC_TYPE_VAR);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
114
common/framework/drivers/cacheinterface.php
Normal file
114
common/framework/drivers/cacheinterface.php
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
namespace Rhymix\Framework\Drivers;
|
||||
|
||||
/**
|
||||
* The cache driver interface.
|
||||
*/
|
||||
interface CacheInterface
|
||||
{
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config);
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isSupported();
|
||||
|
||||
/**
|
||||
* Validate cache settings.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param mixed $config
|
||||
* @return bool
|
||||
*/
|
||||
public static function validateSettings($config);
|
||||
|
||||
/**
|
||||
* Get the value of a key.
|
||||
*
|
||||
* This method returns null if the key was not found.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key);
|
||||
|
||||
/**
|
||||
* Set the value to a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* $ttl is measured in seconds. If it is zero, the key should not expire.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int $ttl
|
||||
* @param bool $force
|
||||
* @return bool
|
||||
*/
|
||||
public function set($key, $value, $ttl = 0, $force = false);
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
* If the key does not exist, it should return false.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($key);
|
||||
|
||||
/**
|
||||
* Check if a key exists.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function exists($key);
|
||||
|
||||
/**
|
||||
* Increase the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function incr($key, $amount);
|
||||
|
||||
/**
|
||||
* Decrease the value of a key by $amount.
|
||||
*
|
||||
* If the key does not exist, this method assumes that the current value is zero.
|
||||
* This method returns the new value.
|
||||
*
|
||||
* @param string $key
|
||||
* @param int $amount
|
||||
* @return int
|
||||
*/
|
||||
public function decr($key, $amount);
|
||||
|
||||
/**
|
||||
* Clear all keys from the cache.
|
||||
*
|
||||
* This method returns true on success and false on failure.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function clear();
|
||||
}
|
||||
|
|
@ -137,7 +137,13 @@ class ConfigParser
|
|||
// Convert cache configuration.
|
||||
if (isset($db_info->use_object_cache))
|
||||
{
|
||||
$config['cache'][] = $db_info->use_object_cache;
|
||||
if (!is_array($db_info->use_object_cache))
|
||||
{
|
||||
$db_info->use_object_cache = array($db_info->use_object_cache);
|
||||
}
|
||||
$config['cache']['type'] = preg_replace('/^memcache$/', 'memcached', preg_replace('/:.+$/', '', array_first($db_info->use_object_cache)));
|
||||
$config['cache']['ttl'] = 86400;
|
||||
$config['cache']['servers'] = in_array($config['cache']['type'], array('memcached', 'redis')) ? $db_info->use_object_cache : array();
|
||||
}
|
||||
|
||||
// Convert FTP configuration.
|
||||
|
|
|
|||
|
|
@ -259,11 +259,16 @@ class Storage
|
|||
*
|
||||
* @param string $filename
|
||||
* @param mixed $data
|
||||
* @param string $comment (optional)
|
||||
* @return string|false
|
||||
*/
|
||||
public static function writePHPData($filename, $data)
|
||||
public static function writePHPData($filename, $data, $comment = null)
|
||||
{
|
||||
return self::write($filename, '<' . '?php return unserialize(' . var_export(serialize($data), true) . ');');
|
||||
if ($comment !== null)
|
||||
{
|
||||
$comment = "/* $comment */\n";
|
||||
}
|
||||
return self::write($filename, '<' . '?php ' . $comment . 'return unserialize(' . var_export(serialize($data), true) . ');');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class adminAdminController extends admin
|
|||
return $output;
|
||||
}
|
||||
|
||||
FileHandler::removeDir('./files/cache/menu/admin_lang/');
|
||||
Rhymix\Framework\Storage::deleteDirectory(\RX_BASEDIR . 'files/cache/menu/admin_lang/');
|
||||
|
||||
$this->setRedirectUrl(Context::get('error_return_url'));
|
||||
}
|
||||
|
|
@ -57,17 +57,16 @@ class adminAdminController extends admin
|
|||
function procAdminRecompileCacheFile()
|
||||
{
|
||||
// rename cache dir
|
||||
$temp_cache_dir = './files/cache_' . $_SERVER['REQUEST_TIME'];
|
||||
FileHandler::rename('./files/cache', $temp_cache_dir);
|
||||
FileHandler::makeDir('./files/cache');
|
||||
Rhymix\Framework\Storage::move(\RX_BASEDIR . 'files/cache', \RX_BASEDIR . 'files/cache_' . time());
|
||||
Rhymix\Framework\Storage::createDirectory(\RX_BASEDIR . 'files/cache');
|
||||
|
||||
// remove module extend cache
|
||||
FileHandler::removeFile(_XE_PATH_ . 'files/config/module_extend.php');
|
||||
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/config/module_extend.php');
|
||||
|
||||
// remove debug files
|
||||
FileHandler::removeFile(_XE_PATH_ . 'files/_debug_message.php');
|
||||
FileHandler::removeFile(_XE_PATH_ . 'files/_debug_db_query.php');
|
||||
FileHandler::removeFile(_XE_PATH_ . 'files/_db_slow_query.php');
|
||||
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/_debug_message.php');
|
||||
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/_debug_db_query.php');
|
||||
Rhymix\Framework\Storage::delete(RX_BASEDIR . 'files/_db_slow_query.php');
|
||||
|
||||
$oModuleModel = getModel('module');
|
||||
$module_list = $oModuleModel->getModuleList();
|
||||
|
|
@ -83,35 +82,41 @@ class adminAdminController extends admin
|
|||
}
|
||||
}
|
||||
|
||||
// remove cache
|
||||
$truncated = array();
|
||||
$oObjectCacheHandler = CacheHandler::getInstance('object');
|
||||
$oTemplateCacheHandler = CacheHandler::getInstance('template');
|
||||
|
||||
if($oObjectCacheHandler->isSupport())
|
||||
// remove object cache
|
||||
if (!in_array(Rhymix\Framework\Cache::getDriverName(), array('file', 'sqlite', 'dummy')))
|
||||
{
|
||||
$truncated[] = $oObjectCacheHandler->truncate();
|
||||
Rhymix\Framework\Cache::clearAll();
|
||||
}
|
||||
|
||||
if($oTemplateCacheHandler->isSupport())
|
||||
{
|
||||
$truncated[] = $oTemplateCacheHandler->truncate();
|
||||
}
|
||||
|
||||
if(count($truncated) && in_array(FALSE, $truncated))
|
||||
{
|
||||
return new Object(-1, 'msg_self_restart_cache_engine');
|
||||
}
|
||||
|
||||
// remove cache dir
|
||||
$tmp_cache_list = FileHandler::readDir('./files', '/(^cache_[0-9]+)/');
|
||||
// remove old cache dir
|
||||
$tmp_cache_list = FileHandler::readDir(\RX_BASEDIR . 'files', '/^(cache_[0-9]+)/');
|
||||
if($tmp_cache_list)
|
||||
{
|
||||
foreach($tmp_cache_list as $tmp_dir)
|
||||
{
|
||||
if($tmp_dir)
|
||||
if(strval($tmp_dir) !== '')
|
||||
{
|
||||
FileHandler::removeDir('./files/' . $tmp_dir);
|
||||
$tmp_dir = \RX_BASEDIR . 'files/' . strval($tmp_dir);
|
||||
if (!Rhymix\Framework\Storage::isDirectory($tmp_dir))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If possible, use system command to speed up recursive deletion
|
||||
if (function_exists('exec') && !preg_match('/(?<!_)exec/', ini_get('disable_functions')))
|
||||
{
|
||||
if (strncasecmp(\PHP_OS, 'win', 3) == 0)
|
||||
{
|
||||
@exec('rmdir /S /Q ' . escapeshellarg($tmp_dir));
|
||||
}
|
||||
else
|
||||
{
|
||||
@exec('rm -rf ' . escapeshellarg($tmp_dir));
|
||||
}
|
||||
}
|
||||
|
||||
// If the directory still exists, delete using PHP.
|
||||
Rhymix\Framework\Storage::deleteDirectory($tmp_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -419,7 +424,7 @@ class adminAdminController extends admin
|
|||
$oModuleModel = getModel('module');
|
||||
$oAdminConfig = $oModuleModel->getModuleConfig('admin');
|
||||
|
||||
FileHandler::removeFile(_XE_PATH_ . $oAdminConfig->adminLogo);
|
||||
Rhymix\Framework\Storage::delete(_XE_PATH_ . $oAdminConfig->adminLogo);
|
||||
unset($oAdminConfig->adminLogo);
|
||||
|
||||
$oModuleController = getController('module');
|
||||
|
|
@ -486,7 +491,7 @@ class adminAdminController extends admin
|
|||
$file_exist = FileHandler::readFile(_XE_PATH_ . 'files/attach/xeicon/' . $virtual_site . $iconname);
|
||||
if($file_exist)
|
||||
{
|
||||
@FileHandler::removeFile(_XE_PATH_ . 'files/attach/xeicon/' . $virtual_site . $iconname);
|
||||
@Rhymix\Framework\Storage::delete(_XE_PATH_ . 'files/attach/xeicon/' . $virtual_site . $iconname);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -667,17 +672,21 @@ class adminAdminController extends admin
|
|||
{
|
||||
if ($vars->object_cache_type === 'memcached' || $vars->object_cache_type === 'redis')
|
||||
{
|
||||
$cache_config = $vars->object_cache_type . '://' . $vars->object_cache_host . ':' . intval($vars->object_cache_port);
|
||||
$cache_servers = array($vars->object_cache_type . '://' . $vars->object_cache_host . ':' . intval($vars->object_cache_port));
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache_config = $vars->object_cache_type;
|
||||
$cache_servers = array();
|
||||
}
|
||||
if (!CacheHandler::isSupport($vars->object_cache_type, $cache_config))
|
||||
if (!Rhymix\Framework\Cache::getDriverInstance($vars->object_cache_type, $cache_servers))
|
||||
{
|
||||
return new Object(-1, 'msg_cache_handler_not_supported');
|
||||
}
|
||||
Rhymix\Framework\Config::set('cache', array($cache_config));
|
||||
Rhymix\Framework\Config::set('cache', array(
|
||||
'type' => $vars->object_cache_type,
|
||||
'ttl' => intval($vars->cache_default_ttl ?: 86400),
|
||||
'servers' => $cache_servers,
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -948,7 +957,7 @@ class adminAdminController extends admin
|
|||
|
||||
if ($deleteIcon)
|
||||
{
|
||||
FileHandler::removeFile($image_filepath.$iconname);
|
||||
Rhymix\Framework\Storage::delete($image_filepath.$iconname);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -956,7 +965,7 @@ class adminAdminController extends admin
|
|||
$icon_filepath = $image_filepath.$iconname;
|
||||
if (file_exists($tmpicon_filepath))
|
||||
{
|
||||
FileHandler::moveFile($tmpicon_filepath, $icon_filepath);
|
||||
Rhymix\Framework\Storage::move($tmpicon_filepath, $icon_filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,10 +50,45 @@ class adminAdminView extends admin
|
|||
|
||||
$this->makeGnbUrl();
|
||||
|
||||
// Check system configuration
|
||||
$this->checkSystemConfiguration();
|
||||
|
||||
// Retrieve the list of installed modules
|
||||
$this->checkEasyinstall();
|
||||
}
|
||||
|
||||
/**
|
||||
* check system configuration
|
||||
* @return void
|
||||
*/
|
||||
function checkSystemConfiguration()
|
||||
{
|
||||
$changed = false;
|
||||
|
||||
// Check encryption keys.
|
||||
if (config('crypto.encryption_key') === null)
|
||||
{
|
||||
config('crypto.encryption_key', Rhymix\Framework\Security::getRandom(64, 'alnum'));
|
||||
$changed = true;
|
||||
}
|
||||
if (config('crypto.authentication_key') === null)
|
||||
{
|
||||
config('crypto.authentication_key', Rhymix\Framework\Security::getRandom(64, 'alnum'));
|
||||
$changed = true;
|
||||
}
|
||||
if (config('crypto.session_key') === null)
|
||||
{
|
||||
config('crypto.session_key', Rhymix\Framework\Security::getRandom(64, 'alnum'));
|
||||
$changed = true;
|
||||
}
|
||||
|
||||
// Save new configuration.
|
||||
if ($changed)
|
||||
{
|
||||
Rhymix\Framework\Config::save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check easy install
|
||||
* @return void
|
||||
|
|
@ -451,19 +486,36 @@ class adminAdminView extends admin
|
|||
Context::set('https_port', Rhymix\Framework\Config::get('url.https_port'));
|
||||
|
||||
// Object cache
|
||||
$object_cache_config = Rhymix\Framework\Config::get('cache');
|
||||
if (is_array($object_cache_config))
|
||||
{
|
||||
$object_cache_config = array_first($object_cache_config);
|
||||
}
|
||||
$object_cache_types = array('apc', 'file', 'memcached', 'redis', 'wincache');
|
||||
$object_cache_type = preg_match('/^(' . implode('|', $object_cache_types) . ')/', $object_cache_config, $matches) ? $matches[1] : '';
|
||||
Context::set('object_cache_types', $object_cache_types);
|
||||
Context::set('object_cache_type', $object_cache_type);
|
||||
$object_cache_types = Rhymix\Framework\Cache::getSupportedDrivers();
|
||||
$object_cache_type = Rhymix\Framework\Config::get('cache.type');
|
||||
if ($object_cache_type)
|
||||
{
|
||||
Context::set('object_cache_host', parse_url($object_cache_config, PHP_URL_HOST) ?: null);
|
||||
Context::set('object_cache_port', parse_url($object_cache_config, PHP_URL_PORT) ?: null);
|
||||
$cache_default_ttl = Rhymix\Framework\Config::get('cache.ttl');
|
||||
$cache_servers = Rhymix\Framework\Config::get('cache.servers');
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache_config = array_first(Rhymix\Framework\Config::get('cache'));
|
||||
if ($cache_config)
|
||||
{
|
||||
$object_cache_type = preg_replace('/^memcache$/', 'memcached', preg_replace('/:.+$/', '', $cache_config));
|
||||
}
|
||||
else
|
||||
{
|
||||
$object_cache_type = 'file';
|
||||
}
|
||||
$cache_default_ttl = 86400;
|
||||
$cache_servers = Rhymix\Framework\Config::get('cache');
|
||||
}
|
||||
|
||||
Context::set('object_cache_types', $object_cache_types);
|
||||
Context::set('object_cache_type', $object_cache_type);
|
||||
Context::set('cache_default_ttl', $cache_default_ttl);
|
||||
|
||||
if ($cache_servers)
|
||||
{
|
||||
Context::set('object_cache_host', parse_url(array_first($cache_servers), PHP_URL_HOST) ?: null);
|
||||
Context::set('object_cache_port', parse_url(array_first($cache_servers), PHP_URL_PORT) ?: null);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ $lang->about_minify_scripts = 'Automatically minify all CSS and JS scripts in th
|
|||
$lang->use_gzip = 'gzip Compression';
|
||||
$lang->delay_session = 'Delay session start';
|
||||
$lang->about_delay_session = 'To improve performance when using a caching proxy server such as Varnish, do not issue sessions to visitors until they log in.<br>Selecting this option may cause view counts and visitor counts to become inaccurate.';
|
||||
$lang->use_object_cache = 'Use Object Cache';
|
||||
$lang->use_object_cache_do_not_use = 'none';
|
||||
$lang->use_object_cache = 'Use Cache';
|
||||
$lang->cache_default_ttl = 'Cache default TTL';
|
||||
$lang->cache_host = 'Host';
|
||||
$lang->cache_port = 'Port';
|
||||
$lang->msg_cache_handler_not_supported = 'Your server does not support the selected cache method, or Rhymix is unable to use the cache with the given settings.';
|
||||
|
|
|
|||
|
|
@ -86,8 +86,7 @@ $lang->about_minify_scripts = 'コアとすべてのモジュールに含まれ
|
|||
$lang->use_gzip = 'gzip 圧縮';
|
||||
$lang->delay_session = 'セッションの開始を遅延';
|
||||
$lang->about_delay_session = 'Varnishなどのプロキシキャッシュサーバ使用時のパフォーマンスを向上させるために、ログインしていないユーザーには、認証セッションを付与しません。<br>このオプションを選択した場合、訪問者数とヒット集計が正確でない場合があります。';
|
||||
$lang->use_object_cache = 'オブジェクトキャッシュ';
|
||||
$lang->use_object_cache_do_not_use = '使用していない';
|
||||
$lang->use_object_cache = 'キャッシュ使用';
|
||||
$lang->cache_host = 'ホスト';
|
||||
$lang->cache_port = 'ポート';
|
||||
$lang->msg_cache_handler_not_supported = '選択したキャッシュ方式をサーバーでサポートされていないか、与えられた情報でキャッシュにアクセスすることができません。';
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ $lang->about_minify_scripts = '코어와 모든 모듈에 포함된 CSS, JS 파
|
|||
$lang->use_gzip = 'gzip 압축';
|
||||
$lang->delay_session = '세션 시작 지연';
|
||||
$lang->about_delay_session = 'Varnish 등의 프록시 캐싱 서버 사용시 성능 개선을 위해, 로그인하지 않은 사용자에게는 인증 세션을 부여하지 않습니다.<br>이 옵션을 선택할 경우 방문자 수 및 조회수 집계가 정확하게 이루어지지 않을 수 있습니다.';
|
||||
$lang->use_object_cache = '오브젝트 캐시 사용';
|
||||
$lang->use_object_cache_do_not_use = '사용하지 않음';
|
||||
$lang->use_object_cache = '캐시 사용';
|
||||
$lang->cache_default_ttl = '캐시 기본 TTL';
|
||||
$lang->cache_host = '호스트';
|
||||
$lang->cache_port = '포트';
|
||||
$lang->msg_cache_handler_not_supported = '선택하신 캐시 방식을 서버에서 지원하지 않거나, 주어진 정보로 캐시에 접속할 수 없습니다.';
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@
|
|||
<label class="x_control-label">{$lang->use_object_cache}</label>
|
||||
<div class="x_controls">
|
||||
<select name="object_cache_type" id="object_cache_type">
|
||||
<option value="">{$lang->use_object_cache_do_not_use}</option>
|
||||
<option value="{$key}" loop="$object_cache_types=>$key" selected="selected"|cond="$key==$object_cache_type">{$key}</option>
|
||||
</select>
|
||||
<div id="object_cache_additional_config" class="x_inline" style="display:none;margin-left:16px">
|
||||
|
|
@ -71,6 +70,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label" for="cache_default_ttl">{$lang->cache_default_ttl}</label>
|
||||
<div class="x_controls">
|
||||
<input type="text" name="cache_default_ttl" id="cache_default_ttl" value="{$cache_default_ttl}" /> {$lang->unit_sec}
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->minify_scripts}</label>
|
||||
<div class="x_controls">
|
||||
|
|
|
|||
|
|
@ -436,12 +436,7 @@ class commentAdminController extends comment
|
|||
$output = executeQuery('comment.deleteModuleCommentsList', $args);
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
// Invalidate newest comments. Per document cache is invalidated inside document admin controller.
|
||||
$oCacheHandler->invalidateGroupKey('newestCommentsList');
|
||||
}
|
||||
Rhymix\Framework\Cache::clearGroup('newestCommentsList');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1227,7 +1227,7 @@ class commentController extends comment
|
|||
// invalid vote if both ip addresses between author's and the current user are same.
|
||||
if($oComment->get('ipaddress') == $_SERVER['REMOTE_ADDR'])
|
||||
{
|
||||
$_SESSION['voted_comment'][$comment_srl] = TRUE;
|
||||
$_SESSION['voted_comment'][$comment_srl] = false;
|
||||
return new Object(-1, $failed_voted);
|
||||
}
|
||||
|
||||
|
|
@ -1241,7 +1241,7 @@ class commentController extends comment
|
|||
// session registered if the author information matches to the current logged-in user's.
|
||||
if($member_srl && $member_srl == $oComment->get('member_srl'))
|
||||
{
|
||||
$_SESSION['voted_comment'][$comment_srl] = TRUE;
|
||||
$_SESSION['voted_comment'][$comment_srl] = false;
|
||||
return new Object(-1, $failed_voted);
|
||||
}
|
||||
}
|
||||
|
|
@ -1264,7 +1264,7 @@ class commentController extends comment
|
|||
// session registered if log info contains recommendation vote log.
|
||||
if($output->data->count)
|
||||
{
|
||||
$_SESSION['voted_comment'][$comment_srl] = TRUE;
|
||||
$_SESSION['voted_comment'][$comment_srl] = false;
|
||||
return new Object(-1, $failed_voted);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -284,12 +284,13 @@ class commentItem extends Object
|
|||
function getVote()
|
||||
{
|
||||
if(!$this->comment_srl) return false;
|
||||
if($_SESSION['voted_comment'][$this->comment_srl])
|
||||
if(isset($_SESSION['voted_comment'][$this->comment_srl]))
|
||||
{
|
||||
return $_SESSION['voted_comment'][$this->comment_srl];
|
||||
}
|
||||
|
||||
$logged_info = Context::get('logged_info');
|
||||
if(!$logged_info->member_srl) return false;
|
||||
|
||||
$args = new stdClass();
|
||||
$args->member_srl = $logged_info->member_srl;
|
||||
|
|
@ -298,10 +299,10 @@ class commentItem extends Object
|
|||
|
||||
if($output->data->point)
|
||||
{
|
||||
return $output->data->point;
|
||||
return $_SESSION['voted_comment'][$this->comment_srl] = $output->data->point;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $_SESSION['voted_comment'][$this->comment_srl] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
13
modules/comment/queries/getCommentVotedLogMulti.xml
Normal file
13
modules/comment/queries/getCommentVotedLogMulti.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<query id="getCommentVotedLog" action="select">
|
||||
<tables>
|
||||
<table name="comment_voted_log" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="comment_srl" />
|
||||
<column name="point" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="in" column="comment_srl" var="comment_srls" filter="number" notnull="notnull" />
|
||||
<condition operation="equal" column="member_srl" var="member_srl" filter="number" pipe="and" />
|
||||
</conditions>
|
||||
</query>
|
||||
|
|
@ -31,13 +31,9 @@ class counterModel extends counter
|
|||
$args->site_srl = $site_srl;
|
||||
|
||||
$iplogged = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'counter:' . $site_srl . '_' . str_replace(array('.', ':'), '-', $args->ipaddress);
|
||||
$cache_key = $oCacheHandler->getGroupKey('counterIpLogged_' . $args->regdate, $object_key);
|
||||
$iplogged = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
$cache_key = 'counter:' . $site_srl . '_' . str_replace(array('.', ':'), '-', $args->ipaddress);
|
||||
$group_key = 'counterIpLogged_' . $args->regdate;
|
||||
$iplogged = Rhymix\Framework\Cache::get($group_key . ':' . $cache_key);
|
||||
|
||||
if($iplogged === false)
|
||||
{
|
||||
|
|
@ -45,9 +41,9 @@ class counterModel extends counter
|
|||
if($output->data->count) $iplogged = TRUE;
|
||||
}
|
||||
|
||||
if($iplogged && $oCacheHandler->isSupport())
|
||||
if($iplogged)
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $iplogged);
|
||||
Rhymix\Framework\Cache::set($group_key . ':' . $cache_key, $iplogged, 0, true);
|
||||
}
|
||||
|
||||
return $iplogged;
|
||||
|
|
@ -64,15 +60,10 @@ class counterModel extends counter
|
|||
$args = new stdClass;
|
||||
$args->regdate = date('Ymd');
|
||||
|
||||
$insertedTodayStatus = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'counter:insertedTodayStatus:' . $site_srl . '_' . $args->regdate;
|
||||
$insertedTodayStatus = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
$cache_key = 'counter:insertedTodayStatus:' . $site_srl . '_' . $args->regdate;
|
||||
$insertedTodayStatus = Rhymix\Framework\Cache::get($cache_key);
|
||||
|
||||
if($insertedTodayStatus === false)
|
||||
if(!$insertedTodayStatus)
|
||||
{
|
||||
if($site_srl)
|
||||
{
|
||||
|
|
@ -86,11 +77,11 @@ class counterModel extends counter
|
|||
|
||||
$insertedTodayStatus = !!$output->data->count;
|
||||
|
||||
if($insertedTodayStatus && $oCacheHandler->isSupport())
|
||||
if($insertedTodayStatus)
|
||||
{
|
||||
$oCacheHandler->put($cache_key, TRUE);
|
||||
Rhymix\Framework\Cache::set($cache_key, true, 0, true);
|
||||
$_old_date = date('Ymd', strtotime('-1 day'));
|
||||
$oCacheHandler->delete('counter:insertedTodayStatus:' . $site_srl . '_' . $_old_date);
|
||||
Rhymix\Framework\Cache::delete('counter:insertedTodayStatus:' . $site_srl . '_' . $_old_date);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -218,15 +218,11 @@ class documentAdminController extends document
|
|||
}
|
||||
|
||||
$oDB->commit();
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
foreach ($document_srl_list as $document_srl)
|
||||
{
|
||||
foreach($document_srl_list as $document_srl)
|
||||
{
|
||||
$cache_key_item = 'document_item:'. getNumberingPath($document_srl) . $document_srl;
|
||||
$oCacheHandler->delete($cache_key_item);
|
||||
}
|
||||
Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document_srl) . $document_srl);
|
||||
}
|
||||
return new Object();
|
||||
}
|
||||
|
|
@ -472,18 +468,11 @@ class documentAdminController extends document
|
|||
$document_srl_list[] = $oDocument->document_srl;
|
||||
}
|
||||
}
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
foreach ($document_srl_list as $document_srl)
|
||||
{
|
||||
if(is_array($document_srl_list))
|
||||
{
|
||||
foreach($document_srl_list as $document_srl)
|
||||
{
|
||||
$cache_key_item = 'document_item:'. getNumberingPath($document_srl) . $document_srl;
|
||||
$oCacheHandler->delete($cache_key_item);
|
||||
}
|
||||
}
|
||||
Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document_srl) . $document_srl);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
@ -690,13 +679,7 @@ class documentAdminController extends document
|
|||
if(!$output->toBool()) return $output;
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_document_extra_keys:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
Rhymix\Framework\Cache::delete("site_and_module:module_document_extra_keys:$module_srl");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -775,15 +775,9 @@ class documentController extends document
|
|||
FileHandler::removeDir(sprintf('files/thumbnails/%s',getNumberingPath($obj->document_srl, 3)));
|
||||
|
||||
$output->add('document_srl',$obj->document_srl);
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
//remove document item from cache
|
||||
$cache_key = 'document_item:'. getNumberingPath($obj->document_srl) . $obj->document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($obj->document_srl) . $obj->document_srl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -919,13 +913,7 @@ class documentController extends document
|
|||
$oDB->commit();
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -1080,13 +1068,7 @@ class documentController extends document
|
|||
$oDB->commit();
|
||||
|
||||
// Clear cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'document_item:'. getNumberingPath($oDocument->document_srl) . $oDocument->document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($oDocument->document_srl) . $oDocument->document_srl);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -1162,13 +1144,8 @@ class documentController extends document
|
|||
|
||||
$oDB->commit();
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
//remove document item from cache
|
||||
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
//remove document item from cache
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl);
|
||||
|
||||
// Register session
|
||||
if(!$_SESSION['banned_document'][$document_srl] && Context::getSessionStatus())
|
||||
|
|
@ -1219,14 +1196,7 @@ class documentController extends document
|
|||
$output = executeQuery('document.updateDocumentExtraVar', $obj);
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_document_extra_keys:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete("site_and_module:module_document_extra_keys:$module_srl");
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -1282,14 +1252,7 @@ class documentController extends document
|
|||
|
||||
$oDB->commit();
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_document_extra_keys:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete("site_and_module:module_document_extra_keys:$module_srl");
|
||||
return new Object();
|
||||
}
|
||||
|
||||
|
|
@ -1362,7 +1325,7 @@ class documentController extends document
|
|||
// Pass if the author's IP address is as same as visitor's.
|
||||
if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR'])
|
||||
{
|
||||
$_SESSION['voted_document'][$document_srl] = true;
|
||||
$_SESSION['voted_document'][$document_srl] = false;
|
||||
return new Object(-1, $failed_voted);
|
||||
}
|
||||
|
||||
|
|
@ -1376,7 +1339,7 @@ class documentController extends document
|
|||
// Pass after registering a session if author's information is same as the currently logged-in user's.
|
||||
if($member_srl && $member_srl == $oDocument->get('member_srl'))
|
||||
{
|
||||
$_SESSION['voted_document'][$document_srl] = true;
|
||||
$_SESSION['voted_document'][$document_srl] = false;
|
||||
return new Object(-1, $failed_voted);
|
||||
}
|
||||
}
|
||||
|
|
@ -1396,7 +1359,7 @@ class documentController extends document
|
|||
// Pass after registering a session if log information has vote-up logs
|
||||
if($output->data->count)
|
||||
{
|
||||
$_SESSION['voted_document'][$document_srl] = true;
|
||||
$_SESSION['voted_document'][$document_srl] = false;
|
||||
return new Object(-1, $failed_voted);
|
||||
}
|
||||
|
||||
|
|
@ -1442,13 +1405,8 @@ class documentController extends document
|
|||
|
||||
$oDB->commit();
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
//remove document item from cache
|
||||
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
//remove document item from cache
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl);
|
||||
|
||||
// Return result
|
||||
$output = new Object();
|
||||
|
|
@ -1617,13 +1575,8 @@ class documentController extends document
|
|||
$args->update_order = -1*getNextSequence();
|
||||
$args->last_updater = $last_updater;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
//remove document item from cache
|
||||
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
// remove document item from cache
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl);
|
||||
}
|
||||
|
||||
return executeQuery('document.updateCommentCount', $args);
|
||||
|
|
@ -1641,13 +1594,8 @@ class documentController extends document
|
|||
$args->document_srl = $document_srl;
|
||||
$args->trackback_count = $trackback_count;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
//remove document item from cache
|
||||
$cache_key = 'document_item:'. getNumberingPath($document_srl) . $document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
// remove document item from cache
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl);
|
||||
|
||||
return executeQuery('document.updateTrackbackCount', $args);
|
||||
}
|
||||
|
|
@ -1752,27 +1700,25 @@ class documentController extends document
|
|||
if(!$output->toBool()) return $output;
|
||||
|
||||
$this->makeCategoryFile($category_info->module_srl);
|
||||
// remvove cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
|
||||
// remove cache
|
||||
$page = 0;
|
||||
while(true)
|
||||
{
|
||||
$page = 0;
|
||||
while(true) {
|
||||
$args = new stdClass();
|
||||
$args->category_srl = $category_srl;
|
||||
$args->list_count = 100;
|
||||
$args->page = ++$page;
|
||||
$output = executeQuery('document.getDocumentList', $args, array('document_srl'));
|
||||
$args = new stdClass();
|
||||
$args->category_srl = $category_srl;
|
||||
$args->list_count = 100;
|
||||
$args->page = ++$page;
|
||||
$output = executeQuery('document.getDocumentList', $args, array('document_srl'));
|
||||
|
||||
if($output->data == array())
|
||||
break;
|
||||
if($output->data == array())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
foreach($output->data as $val)
|
||||
{
|
||||
//remove document item from cache
|
||||
$cache_key = 'document_item:'. getNumberingPath($val->document_srl) . $val->document_srl;
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
foreach($output->data as $val)
|
||||
{
|
||||
Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($val->document_srl) . $val->document_srl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,32 +79,35 @@ class documentItem extends Object
|
|||
$document_item = false;
|
||||
$cache_put = false;
|
||||
$columnList = array();
|
||||
$reload_counts = true;
|
||||
|
||||
if ($this->columnList === false)
|
||||
{
|
||||
$reload_counts = false;
|
||||
}
|
||||
$this->columnList = array();
|
||||
|
||||
// cache controll
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
$cache_key = 'document_item:' . getNumberingPath($this->document_srl) . $this->document_srl;
|
||||
$document_item = Rhymix\Framework\Cache::get($cache_key);
|
||||
if($document_item)
|
||||
{
|
||||
$cache_key = 'document_item:' . getNumberingPath($this->document_srl) . $this->document_srl;
|
||||
$document_item = $oCacheHandler->get($cache_key);
|
||||
if($document_item !== false)
|
||||
{
|
||||
$columnList = array('readed_count', 'voted_count', 'blamed_count', 'comment_count', 'trackback_count');
|
||||
}
|
||||
$columnList = array('readed_count', 'voted_count', 'blamed_count', 'comment_count', 'trackback_count');
|
||||
}
|
||||
|
||||
$args = new stdClass();
|
||||
$args->document_srl = $this->document_srl;
|
||||
$output = executeQuery('document.getDocument', $args, $columnList);
|
||||
if(!$document_item || $reload_counts)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->document_srl = $this->document_srl;
|
||||
$output = executeQuery('document.getDocument', $args, $columnList);
|
||||
}
|
||||
|
||||
if($document_item === false)
|
||||
if(!$document_item)
|
||||
{
|
||||
$document_item = $output->data;
|
||||
|
||||
//insert in cache
|
||||
if($document_item && $oCacheHandler->isSupport())
|
||||
if($document_item)
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $document_item);
|
||||
Rhymix\Framework\Cache::set($cache_key, $document_item);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -372,12 +375,13 @@ class documentItem extends Object
|
|||
function getVoted()
|
||||
{
|
||||
if(!$this->document_srl) return false;
|
||||
if($_SESSION['voted_document'][$this->document_srl])
|
||||
if(isset($_SESSION['voted_document'][$this->document_srl]))
|
||||
{
|
||||
return $_SESSION['voted_document'][$this->document_srl];
|
||||
}
|
||||
|
||||
$logged_info = Context::get('logged_info');
|
||||
if(!$logged_info->member_srl) return false;
|
||||
|
||||
$args = new stdClass();
|
||||
$args->member_srl = $logged_info->member_srl;
|
||||
|
|
@ -386,10 +390,10 @@ class documentItem extends Object
|
|||
|
||||
if($output->data->point)
|
||||
{
|
||||
return $output->data->point;
|
||||
return $_SESSION['voted_document'][$this->document_srl] = $output->data->point;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $_SESSION['voted_document'][$this->document_srl] = false;
|
||||
}
|
||||
|
||||
function getTitle($cut_size = 0, $tail='...')
|
||||
|
|
@ -761,6 +765,7 @@ class documentItem extends Object
|
|||
$oCommentModel = getModel('comment');
|
||||
$output = $oCommentModel->getCommentList($this->document_srl, $cpage, $is_admin);
|
||||
if(!$output->toBool() || !count($output->data)) return;
|
||||
|
||||
// Create commentItem object from a comment list
|
||||
// If admin priviledge is granted on parent posts, you can read its child posts.
|
||||
$accessible = array();
|
||||
|
|
@ -782,6 +787,39 @@ class documentItem extends Object
|
|||
}
|
||||
$comment_list[$val->comment_srl] = $oCommentItem;
|
||||
}
|
||||
|
||||
// Cache the vote log for all comments.
|
||||
$logged_info = Context::get('logged_info');
|
||||
if ($logged_info->member_srl)
|
||||
{
|
||||
$comment_srls = array();
|
||||
foreach ($comment_list as $comment_srl => $comment)
|
||||
{
|
||||
if (!isset($_SESSION['voted_comment'][$comment_srl]))
|
||||
{
|
||||
$comment_srls[] = $comment_srl;
|
||||
}
|
||||
}
|
||||
if (count($comment_srls))
|
||||
{
|
||||
$output = executeQuery('comment.getCommentVotedLogMulti', (object)array(
|
||||
'comment_srls' => $comment_srls,
|
||||
'member_srl' => $logged_info->member_srl,
|
||||
));
|
||||
foreach ($output->data as $data)
|
||||
{
|
||||
$_SESSION['voted_comment'][$data->comment_srl] = $data->point;
|
||||
}
|
||||
foreach ($comment_srls as $comment_srl)
|
||||
{
|
||||
if (!isset($_SESSION['voted_comment'][$comment_srl]))
|
||||
{
|
||||
$_SESSION['voted_comment'][$comment_srl] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Variable setting to be displayed on the skin
|
||||
Context::set($cpageStr, $output->page_navigation->cur_page);
|
||||
Context::set('cpage', $output->page_navigation->cur_page);
|
||||
|
|
|
|||
|
|
@ -370,18 +370,10 @@ class documentModel extends document
|
|||
{
|
||||
if(!isset($GLOBALS['XE_EXTRA_KEYS'][$module_srl]))
|
||||
{
|
||||
$keys = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_document_extra_keys:' . $module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$keys = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
$keys = Rhymix\Framework\Cache::get("site_and_module:module_document_extra_keys:$module_srl");
|
||||
$oExtraVar = ExtraVar::getInstance($module_srl);
|
||||
|
||||
if($keys === false)
|
||||
if($keys === null)
|
||||
{
|
||||
$obj = new stdClass();
|
||||
$obj->module_srl = $module_srl;
|
||||
|
|
@ -437,10 +429,7 @@ class documentModel extends document
|
|||
$keys = $oExtraVar->getExtraVars();
|
||||
if(!$keys) $keys = array();
|
||||
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $keys);
|
||||
}
|
||||
Rhymix\Framework\Cache::set("site_and_module:module_document_extra_keys:$module_srl", $keys, 0, true);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -149,6 +149,11 @@ class installController extends install
|
|||
$config['db']['master']['prefix'] .= '_';
|
||||
}
|
||||
|
||||
// Create new crypto keys.
|
||||
$config['crypto']['encryption_key'] = Rhymix\Framework\Security::getRandom(64, 'alnum');
|
||||
$config['crypto']['authentication_key'] = Rhymix\Framework\Security::getRandom(64, 'alnum');
|
||||
$config['crypto']['session_key'] = Rhymix\Framework\Security::getRandom(64, 'alnum');
|
||||
|
||||
// Set the default language.
|
||||
$config['locale']['default_lang'] = Context::getLangType();
|
||||
$config['locale']['enabled_lang'] = array($config['locale']['default_lang']);
|
||||
|
|
|
|||
|
|
@ -178,11 +178,7 @@ class layoutAdminController extends layout
|
|||
$output = executeQuery('layout.updateModuleLayout', $update_args);
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -263,6 +259,7 @@ class layoutAdminController extends layout
|
|||
$oLayoutModel = getModel('layout');
|
||||
$cache_file = $oLayoutModel->getUserLayoutCache($args->layout_srl, Context::getLangType());
|
||||
FileHandler::removeFile($cache_file);
|
||||
Rhymix\Framework\Cache::delete('layout:' . $args->layout_srl);
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
|
@ -326,10 +323,13 @@ class layoutAdminController extends layout
|
|||
|
||||
$layout_file = $oLayoutModel->getUserLayoutHtml($layout_srl);
|
||||
FileHandler::removeFile($layout_file);
|
||||
|
||||
// Delete Layout
|
||||
$args = new stdClass();
|
||||
$args->layout_srl = $layout_srl;
|
||||
$output = executeQuery("layout.deleteLayout", $args);
|
||||
|
||||
Rhymix\Framework\Cache::delete('layout:' . $args->layout_srl);
|
||||
|
||||
if(!$output->toBool()) return $output;
|
||||
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ class layout extends ModuleObject
|
|||
$args->layout = implode('|@|', $layout_path);
|
||||
$args->layout_srl = $layout->layout_srl;
|
||||
$output = executeQuery('layout.updateLayout', $args);
|
||||
Rhymix\Framework\Cache::delete('layout:' . $args->layout_srl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -258,6 +258,13 @@ class layoutModel extends layout
|
|||
*/
|
||||
function getLayout($layout_srl)
|
||||
{
|
||||
// Get information from cache
|
||||
$layout_info = Rhymix\Framework\Cache::get("layout:$layout_srl");
|
||||
if ($layout_info !== null)
|
||||
{
|
||||
return $layout_info;
|
||||
}
|
||||
|
||||
// Get information from the DB
|
||||
$args = new stdClass();
|
||||
$args->layout_srl = $layout_srl;
|
||||
|
|
@ -267,6 +274,8 @@ class layoutModel extends layout
|
|||
// Return xml file informaton after listing up the layout and extra_vars
|
||||
$layout_info = $this->getLayoutInfo($layout, $output->data, $output->data->layout_type);
|
||||
|
||||
// Store in cache
|
||||
Rhymix\Framework\Cache::set("layout:$layout_srl", $layout_info);
|
||||
return $layout_info;
|
||||
}
|
||||
|
||||
|
|
@ -484,7 +493,7 @@ class layoutModel extends layout
|
|||
{
|
||||
$cache_file = $this->getUserLayoutCache($layout_srl, Context::getLangType());
|
||||
}
|
||||
|
||||
|
||||
if(file_exists($cache_file)&&filemtime($cache_file)>filemtime($xml_file))
|
||||
{
|
||||
include($cache_file);
|
||||
|
|
|
|||
|
|
@ -1330,11 +1330,7 @@ class memberAdminController extends member
|
|||
function _deleteMemberGroupCache($site_srl = 0)
|
||||
{
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('member');
|
||||
}
|
||||
Rhymix\Framework\Cache::clearGroup('member');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2976,27 +2976,12 @@ class memberController extends member
|
|||
|
||||
function _clearMemberCache($member_srl, $site_srl = 0)
|
||||
{
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
$member_srl = getNumberingPath($member_srl) . $member_srl;
|
||||
Rhymix\Framework\Cache::delete("member:member_info:$member_srl");
|
||||
Rhymix\Framework\Cache::delete("member:member_groups:$member_srl:site:$site_srl");
|
||||
if ($site_srl != 0)
|
||||
{
|
||||
$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_' . $site_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
|
||||
if($site_srl !== 0)
|
||||
{
|
||||
$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
Rhymix\Framework\Cache::delete("member:member_groups:$member_srl:site:0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -326,31 +326,21 @@ class memberModel extends member
|
|||
//columnList size zero... get full member info
|
||||
if(!$GLOBALS['__member_info__'][$member_srl] || count($columnList) == 0)
|
||||
{
|
||||
$GLOBALS['__member_info__'][$member_srl] = false;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$columnList = array();
|
||||
$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$GLOBALS['__member_info__'][$member_srl] = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
if($GLOBALS['__member_info__'][$member_srl] === false)
|
||||
$cache_key = 'member:member_info:' . getNumberingPath($member_srl) . $member_srl;
|
||||
$GLOBALS['__member_info__'][$member_srl] = Rhymix\Framework\Cache::get($cache_key);
|
||||
if(!$GLOBALS['__member_info__'][$member_srl])
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->member_srl = $member_srl;
|
||||
$output = executeQuery('member.getMemberInfoByMemberSrl', $args, $columnList);
|
||||
if(!$output->data)
|
||||
{
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, new stdClass);
|
||||
Rhymix\Framework\Cache::set($cache_key, new stdClass);
|
||||
return new stdClass;
|
||||
}
|
||||
|
||||
$this->arrangeMemberInfo($output->data, $site_srl);
|
||||
|
||||
//insert in cache
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $GLOBALS['__member_info__'][$member_srl]);
|
||||
Rhymix\Framework\Cache::set($cache_key, $GLOBALS['__member_info__'][$member_srl]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -367,7 +357,6 @@ class memberModel extends member
|
|||
$oModuleModel = getModel('module');
|
||||
$config = $oModuleModel->getModuleConfig('member');
|
||||
|
||||
|
||||
$info->profile_image = $this->getProfileImage($info->member_srl);
|
||||
$info->image_name = $this->getImageName($info->member_srl);
|
||||
$info->image_mark = $this->getImageMark($info->member_srl);
|
||||
|
|
@ -494,18 +483,12 @@ class memberModel extends member
|
|||
static $member_groups = array();
|
||||
|
||||
// cache controll
|
||||
$group_list = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_'.$site_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$group_list = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
$cache_key = 'member:member_groups:' . getNumberingPath($member_srl) . $member_srl . ':site:' . $site_srl;
|
||||
$group_list = Rhymix\Framework\Cache::get($cache_key);
|
||||
|
||||
if(!$member_groups[$member_srl][$site_srl] || $force_reload)
|
||||
{
|
||||
if($group_list === false)
|
||||
if(!$group_list)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->member_srl = $member_srl;
|
||||
|
|
@ -513,7 +496,7 @@ class memberModel extends member
|
|||
$output = executeQueryArray('member.getMemberGroups', $args);
|
||||
$group_list = $output->data;
|
||||
//insert in cache
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $group_list);
|
||||
Rhymix\Framework\Cache::set($cache_key, $group_list, 0, true);
|
||||
}
|
||||
if(!$group_list) return array();
|
||||
|
||||
|
|
@ -550,26 +533,15 @@ class memberModel extends member
|
|||
*/
|
||||
function getDefaultGroup($site_srl = 0, $columnList = array())
|
||||
{
|
||||
$default_group = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$columnList = array();
|
||||
$object_key = 'default_group_' . $site_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$default_group = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
$default_group = Rhymix\Framework\Cache::get("member:default_group:$site_srl");
|
||||
|
||||
if($default_group === false)
|
||||
if(!$default_group)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->site_srl = $site_srl;
|
||||
$output = executeQuery('member.getDefaultGroup', $args, $columnList);
|
||||
$default_group = $output->data;
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $default_group);
|
||||
}
|
||||
Rhymix\Framework\Cache::set("member:default_group:$site_srl", $default_group, 0, true);
|
||||
}
|
||||
|
||||
return $default_group;
|
||||
|
|
@ -609,16 +581,9 @@ class memberModel extends member
|
|||
$site_srl = 0;
|
||||
}
|
||||
|
||||
$group_list = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'member_groups:site_'.$site_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$group_list = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
$group_list = Rhymix\Framework\Cache::get("member:member_groups:site:$site_srl");
|
||||
|
||||
if($group_list === false)
|
||||
if(!$group_list)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->site_srl = $site_srl;
|
||||
|
|
@ -626,8 +591,7 @@ class memberModel extends member
|
|||
$args->order_type = 'asc';
|
||||
$output = executeQueryArray('member.getGroups', $args);
|
||||
$group_list = $output->data;
|
||||
//insert in cache
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $group_list);
|
||||
Rhymix\Framework\Cache::set("member:member_groups:site:$site_srl", $group_list, 0, true);
|
||||
}
|
||||
|
||||
if(!$group_list)
|
||||
|
|
@ -635,7 +599,6 @@ class memberModel extends member
|
|||
return array();
|
||||
}
|
||||
|
||||
|
||||
foreach($group_list as $val)
|
||||
{
|
||||
$result[$val->group_srl] = $val;
|
||||
|
|
|
|||
|
|
@ -209,12 +209,7 @@ class menuAdminController extends menu
|
|||
return $output;
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
$oMenuAdminController = getAdminController('menu');
|
||||
$oMenuAdminController->makeXmlFile($menuSrl);
|
||||
|
||||
|
|
|
|||
|
|
@ -294,11 +294,7 @@ class module extends ModuleObject
|
|||
$module_info->admin_id = null;
|
||||
executeQuery('module.updateModule', $module_info);
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
}
|
||||
}
|
||||
// Various column drop
|
||||
|
|
|
|||
|
|
@ -28,13 +28,7 @@ class moduleController extends module
|
|||
|
||||
$output = executeQuery('module.insertActionForward', $args);
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'action_forward';
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete('action_forward');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -50,13 +44,7 @@ class moduleController extends module
|
|||
|
||||
$output = executeQuery('module.deleteActionForward', $args);
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'action_forward';
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete('action_forward');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -92,12 +80,7 @@ class moduleController extends module
|
|||
{
|
||||
//remove from cache
|
||||
$GLOBALS['__triggers__'] = NULL;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'triggers';
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
Rhymix\Framework\Cache::delete('triggers');
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
|
@ -121,12 +104,7 @@ class moduleController extends module
|
|||
{
|
||||
//remove from cache
|
||||
$GLOBALS['__triggers__'] = NULL;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'triggers';
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
Rhymix\Framework\Cache::delete('triggers');
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
|
@ -146,12 +124,7 @@ class moduleController extends module
|
|||
{
|
||||
//remove from cache
|
||||
$GLOBALS['__triggers__'] = NULL;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'triggers';
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
Rhymix\Framework\Cache::delete('triggers');
|
||||
}
|
||||
|
||||
return $output;
|
||||
|
|
@ -253,11 +226,7 @@ class moduleController extends module
|
|||
$output = executeQuery('module.insertModuleConfig', $args);
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -278,12 +247,7 @@ class moduleController extends module
|
|||
$output = executeQuery('module.insertModulePartConfig', $args);
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -353,12 +317,7 @@ class moduleController extends module
|
|||
$module_info = $oModuleModel->getModuleInfoByModuleSrl($args->index_module_srl);
|
||||
$mid = $module_info->mid;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -519,12 +478,8 @@ class moduleController extends module
|
|||
// commit
|
||||
$oDB->commit();
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
|
||||
$output->add('module_srl',$args->module_srl);
|
||||
return $output;
|
||||
}
|
||||
|
|
@ -644,12 +599,7 @@ class moduleController extends module
|
|||
$output->add('module_srl',$args->module_srl);
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -666,12 +616,7 @@ class moduleController extends module
|
|||
if(!$output->toBool()) return $output;
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -795,11 +740,7 @@ class moduleController extends module
|
|||
$oDB->commit();
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -820,12 +761,7 @@ class moduleController extends module
|
|||
$output = executeQuery('module.clearDefaultModule');
|
||||
if(!$output->toBool()) return $output;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -836,12 +772,7 @@ class moduleController extends module
|
|||
{
|
||||
$output = executeQuery('module.updateModuleMenu', $args);
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -857,12 +788,7 @@ class moduleController extends module
|
|||
$args->menu_srls = implode(',',$menu_srl_list);
|
||||
$output = executeQuery('module.updateModuleLayout', $args);
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -1054,23 +980,17 @@ class moduleController extends module
|
|||
|
||||
if($mode === 'P')
|
||||
{
|
||||
$object_key = 'module_skin_vars:'.$module_srl;
|
||||
$object_key = 'site_and_module:module_skin_vars:' . $module_srl;
|
||||
$query = 'module.deleteModuleSkinVars';
|
||||
}
|
||||
else
|
||||
{
|
||||
$object_key = 'module_mobile_skin_vars:'.$module_srl;
|
||||
$object_key = 'site_and_module:module_mobile_skin_vars:' . $module_srl;
|
||||
$query = 'module.deleteModuleMobileSkinVars';
|
||||
}
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete($object_key);
|
||||
return executeQuery($query, $args);
|
||||
}
|
||||
|
||||
|
|
@ -1094,14 +1014,8 @@ class moduleController extends module
|
|||
if(!$args->name || !$args->value) continue;
|
||||
$output = executeQuery('module.insertModuleExtraVars', $args);
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_extra_vars:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete("site_and_module:module_extra_vars:$module_srl");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1114,14 +1028,7 @@ class moduleController extends module
|
|||
$output = executeQuery('module.deleteModuleExtraVars', $args);
|
||||
|
||||
//remove from cache
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_extra_vars:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::delete("site_and_module:module_extra_vars:$module_srl");
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -1426,12 +1333,7 @@ class moduleController extends module
|
|||
$args->site_srls = $site_srls;
|
||||
$output = executeQuery('module.updateModuleInSites', $args);
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,26 +115,17 @@ class moduleModel extends module
|
|||
}
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
// If domain is set, look for subsite
|
||||
if($domain !== '')
|
||||
{
|
||||
$site_info = false;
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'site_info:' . md5($domain);
|
||||
$domain_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$site_info = $oCacheHandler->get($domain_cache_key);
|
||||
}
|
||||
|
||||
if($site_info === false)
|
||||
$site_info = Rhymix\Framework\Cache::get('site_and_module:site_info:' . md5($domain));
|
||||
if($site_info === null)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->domain = $domain;
|
||||
$output = executeQuery('module.getSiteInfoByDomain', $args);
|
||||
$site_info = $output->data;
|
||||
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($domain_cache_key, $site_info);
|
||||
Rhymix\Framework\Cache::set('site_and_module:site_info:' . md5($domain), $site_info, 0, true);
|
||||
}
|
||||
|
||||
if($site_info && $vid)
|
||||
|
|
@ -148,15 +139,8 @@ class moduleModel extends module
|
|||
// If no virtual website was found, get default website
|
||||
if($domain === '')
|
||||
{
|
||||
$site_info = false;
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'default_site';
|
||||
$default_site_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$site_info = $oCacheHandler->get($default_site_cache_key);
|
||||
}
|
||||
|
||||
if($site_info === false)
|
||||
$site_info = Rhymix\Framework\Cache::get('site_and_module:default_site');
|
||||
if($site_info === null)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->site_srl = 0;
|
||||
|
|
@ -193,7 +177,7 @@ class moduleModel extends module
|
|||
$output = executeQuery('module.getSiteInfo', $args);
|
||||
}
|
||||
$site_info = $output->data;
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($default_site_cache_key, $site_info);
|
||||
Rhymix\Framework\Cache::set('site_and_module:default_site', $site_info, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -216,35 +200,23 @@ class moduleModel extends module
|
|||
$args->mid = $mid;
|
||||
$args->site_srl = (int)$site_srl;
|
||||
|
||||
$module_srl = false;
|
||||
$module_info = false;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
$module_srl = Rhymix\Framework\Cache::get('site_and_module:module_srl:' . $mid . '_' . $site_srl);
|
||||
if($module_srl)
|
||||
{
|
||||
$object_key = 'module_srl:'.$mid.'_'.$site_srl;
|
||||
$module_srl_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$module_srl = $oCacheHandler->get($module_srl_cache_key);
|
||||
if($module_srl)
|
||||
{
|
||||
$object_key = 'mid_info:' . $module_srl;
|
||||
$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$module_info = $oCacheHandler->get($module_info_cache_key);
|
||||
}
|
||||
$module_info = Rhymix\Framework\Cache::get('site_and_module:mid_info:' . $module_srl);
|
||||
}
|
||||
|
||||
if($module_info === false)
|
||||
else
|
||||
{
|
||||
$module_info = null;
|
||||
}
|
||||
|
||||
if($module_info === null)
|
||||
{
|
||||
$output = executeQuery('module.getMidInfo', $args);
|
||||
$module_info = $output->data;
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($module_srl_cache_key, $module_info->module_srl);
|
||||
|
||||
$object_key = 'mid_info:' . $module_info->module_srl;
|
||||
$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->put($module_info_cache_key, $module_info);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::set('site_and_module:module_srl:' . $mid . '_' . $site_srl, $module_info->module_srl, 0, true);
|
||||
Rhymix\Framework\Cache::set('site_and_module:mid_info:' . $module_info->module_srl, $module_info, 0, true);
|
||||
}
|
||||
|
||||
$this->applyDefaultSkin($module_info);
|
||||
|
|
@ -317,35 +289,25 @@ class moduleModel extends module
|
|||
$moduleInfo->designSettings->skin->mobileIsDefault = $moduleInfo->is_mskin_fix == 'N' ? 1 : 0;
|
||||
$moduleInfo->designSettings->skin->mobile = $skinInfoMobile->title;
|
||||
|
||||
$module_srl = false;
|
||||
$mid_info = false;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
$module_srl = Rhymix\Framework\Cache::get('site_and_module:module_srl:' . $mid . '_' . $site_srl);
|
||||
if($module_srl)
|
||||
{
|
||||
$object_key = 'module_srl:'.$mid.'_'.$site_srl;
|
||||
$module_srl_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$module_srl = $oCacheHandler->get($module_srl_cache_key);
|
||||
if($module_srl)
|
||||
{
|
||||
$object_key = 'mid_info:' . $module_srl;
|
||||
$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$mid_info = $oCacheHandler->get($module_info_cache_key);
|
||||
}
|
||||
|
||||
if($mid_info === false)
|
||||
{
|
||||
$oCacheHandler->put($module_srl_cache_key, $output->data->module_srl);
|
||||
|
||||
$object_key = 'mid_info:' . $output->data->module_srl;
|
||||
$module_info_cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->put($module_info_cache_key, $moduleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mid_info->designSettings = $moduleInfo->designSettings;
|
||||
$moduleInfo = $mid_info;
|
||||
}
|
||||
$mid_info = Rhymix\Framework\Cache::get('site_and_module:mid_info:' . $module_srl);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mid_info = null;
|
||||
}
|
||||
|
||||
if($mid_info === null)
|
||||
{
|
||||
Rhymix\Framework\Cache::set('site_and_module:module_srl:' . $mid . '_' . $site_srl, $output->data->module_srl, 0, true);
|
||||
Rhymix\Framework\Cache::set('site_and_module:mid_info:' . $output->data->module_srl, $moduleInfo, 0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
$mid_info->designSettings = $moduleInfo->designSettings;
|
||||
$moduleInfo = $mid_info;
|
||||
}
|
||||
|
||||
$moduleInfo = $this->addModuleExtraVars($moduleInfo);
|
||||
|
|
@ -366,27 +328,17 @@ class moduleModel extends module
|
|||
*/
|
||||
function getModuleInfoByModuleSrl($module_srl, $columnList = array())
|
||||
{
|
||||
$mid_info = false;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'mid_info:' . $module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$mid_info = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
if($mid_info === false)
|
||||
$mid_info = Rhymix\Framework\Cache::get("site_and_module:mid_info:$module_srl");
|
||||
if($mid_info === null)
|
||||
{
|
||||
// Get data
|
||||
$args = new stdClass();
|
||||
$args->module_srl = $module_srl;
|
||||
$output = executeQuery('module.getMidInfo', $args);
|
||||
if(!$output->toBool()) return;
|
||||
|
||||
$mid_info = $output->data;
|
||||
$this->applyDefaultSkin($mid_info);
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $mid_info);
|
||||
Rhymix\Framework\Cache::set("site_and_module:mid_info:$module_srl", $mid_info, 0, true);
|
||||
}
|
||||
|
||||
if($mid_info && count($columnList))
|
||||
|
|
@ -498,21 +450,10 @@ class moduleModel extends module
|
|||
*/
|
||||
function getMidList($args = null, $columnList = array())
|
||||
{
|
||||
$list = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
$list = Rhymix\Framework\Cache::get('site_and_module:module:mid_list_' . $args->site_srl);
|
||||
if($list === null)
|
||||
{
|
||||
if(count($args) === 1 && isset($args->site_srl))
|
||||
{
|
||||
$object_key = 'module:mid_list_' . $args->site_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$list = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
}
|
||||
|
||||
if($list === false)
|
||||
{
|
||||
if($oCacheHandler->isSupport() && count($args) === 1 && isset($args->site_srl))
|
||||
{
|
||||
$columnList = array();
|
||||
}
|
||||
|
|
@ -521,11 +462,12 @@ class moduleModel extends module
|
|||
if(!$output->toBool()) return $output;
|
||||
$list = $output->data;
|
||||
|
||||
if($oCacheHandler->isSupport() && count($args) === 1 && isset($args->site_srl))
|
||||
if(count($args) === 1 && isset($args->site_srl))
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $list);
|
||||
Rhymix\Framework\Cache::set('site_and_module:module:mid_list_' . $args->site_srl, $list, 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$list) return;
|
||||
|
||||
if(!is_array($list)) $list = array($list);
|
||||
|
|
@ -585,17 +527,8 @@ class moduleModel extends module
|
|||
*/
|
||||
function getActionForward($act)
|
||||
{
|
||||
$action_forward = false;
|
||||
// cache controll
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'action_forward';
|
||||
$action_forward = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
// retrieve and caching all registered action_forward
|
||||
if($action_forward === false)
|
||||
$action_forward = Rhymix\Framework\Cache::get('action_forward');
|
||||
if($action_forward === null)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$output = executeQueryArray('module.getActionForward',$args);
|
||||
|
|
@ -607,11 +540,8 @@ class moduleModel extends module
|
|||
{
|
||||
$action_forward[$item->act] = $item;
|
||||
}
|
||||
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $action_forward);
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::set('action_forward', $action_forward, 0, true);
|
||||
}
|
||||
|
||||
if($action_forward[$act])
|
||||
|
|
@ -646,20 +576,14 @@ class moduleModel extends module
|
|||
{
|
||||
if(is_null($GLOBALS['__triggers__']))
|
||||
{
|
||||
$triggers = FALSE;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', NULL, TRUE);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_key = 'triggers';
|
||||
$triggers = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
if($triggers === FALSE)
|
||||
$triggers = Rhymix\Framework\Cache::get('triggers');
|
||||
if($triggers === null)
|
||||
{
|
||||
$output = executeQueryArray('module.getTriggers');
|
||||
$triggers = $output->data;
|
||||
if($output->toBool() && $oCacheHandler->isSupport())
|
||||
if($output->toBool())
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $triggers);
|
||||
Rhymix\Framework\Cache::set('triggers', $triggers, 0, true);
|
||||
}
|
||||
}
|
||||
foreach($triggers as $item)
|
||||
|
|
@ -1380,17 +1304,8 @@ class moduleModel extends module
|
|||
*/
|
||||
function getModuleConfig($module, $site_srl = 0)
|
||||
{
|
||||
$config = false;
|
||||
// cache controll
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_config:' . $module . '_' . $site_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$config = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
if($config === false)
|
||||
$config = Rhymix\Framework\Cache::get('site_and_module:module_config:' . $module . '_' . $site_srl);
|
||||
if($config === null)
|
||||
{
|
||||
if(!$GLOBALS['__ModuleConfig__'][$site_srl][$module])
|
||||
{
|
||||
|
|
@ -1402,10 +1317,7 @@ class moduleModel extends module
|
|||
else $config = new stdClass;
|
||||
|
||||
//insert in cache
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $config);
|
||||
}
|
||||
Rhymix\Framework\Cache::set('site_and_module:module_config:' . $module . '_' . $site_srl, $config, 0, true);
|
||||
$GLOBALS['__ModuleConfig__'][$site_srl][$module] = $config;
|
||||
}
|
||||
return $GLOBALS['__ModuleConfig__'][$site_srl][$module];
|
||||
|
|
@ -1420,17 +1332,8 @@ class moduleModel extends module
|
|||
*/
|
||||
function getModulePartConfig($module, $module_srl)
|
||||
{
|
||||
$config = false;
|
||||
// cache controll
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_part_config:'.$module.'_'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$config = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
if($config === false)
|
||||
$config = Rhymix\Framework\Cache::get('site_and_module:module_part_config:' . $module . '_' . $module_srl);
|
||||
if($config === null)
|
||||
{
|
||||
if(!isset($GLOBALS['__ModulePartConfig__'][$module][$module_srl]))
|
||||
{
|
||||
|
|
@ -1442,16 +1345,13 @@ class moduleModel extends module
|
|||
else $config = null;
|
||||
|
||||
//insert in cache
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($cache_key, $config);
|
||||
}
|
||||
Rhymix\Framework\Cache::set('site_and_module:module_part_config:' . $module . '_' . $module_srl, $config === null ? 0 : $config, 0, true);
|
||||
$GLOBALS['__ModulePartConfig__'][$module][$module_srl] = $config;
|
||||
}
|
||||
return $GLOBALS['__ModulePartConfig__'][$module][$module_srl];
|
||||
}
|
||||
|
||||
return $config;
|
||||
return $config === 0 ? null : $config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1741,30 +1641,17 @@ class moduleModel extends module
|
|||
$get_module_srls = array();
|
||||
if(!is_array($list_module_srl)) $list_module_srl = array($list_module_srl);
|
||||
|
||||
$vars = false;
|
||||
// cache controll
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
foreach($list_module_srl as $module_srl)
|
||||
{
|
||||
foreach($list_module_srl as $module_srl)
|
||||
$vars = Rhymix\Framework\Cache::get("site_and_module:module_extra_vars:$module_srl");
|
||||
if($vars !== null)
|
||||
{
|
||||
$object_key = 'module_extra_vars:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$vars = $oCacheHandler->get($cache_key);
|
||||
|
||||
if($vars)
|
||||
{
|
||||
$extra_vars[$module_srl] = $vars;
|
||||
}
|
||||
else
|
||||
{
|
||||
$get_module_srls[] = $module_srl;
|
||||
}
|
||||
$extra_vars[$module_srl] = $vars;
|
||||
}
|
||||
else
|
||||
{
|
||||
$get_module_srls[] = $module_srl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$get_module_srls = $list_module_srl;
|
||||
}
|
||||
|
||||
if(count($get_module_srls) > 0)
|
||||
|
|
@ -1782,6 +1669,7 @@ class moduleModel extends module
|
|||
{
|
||||
foreach($get_module_srls as $module_srl)
|
||||
{
|
||||
Rhymix\Framework\Cache::set("site_and_module:module_extra_vars:$module_srl", new stdClass, 0, true);
|
||||
$extra_vars[$module_srl] = new stdClass;
|
||||
}
|
||||
}
|
||||
|
|
@ -1795,12 +1683,7 @@ class moduleModel extends module
|
|||
}
|
||||
$extra_vars[$val->module_srl]->{$val->name} = $val->value;
|
||||
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_extra_vars:'.$val->module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->put($cache_key, $extra_vars[$val->module_srl]);
|
||||
}
|
||||
Rhymix\Framework\Cache::set('site_and_module:module_extra_vars:' . $val->module_srl, $extra_vars[$val->module_srl], 0, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1812,16 +1695,8 @@ class moduleModel extends module
|
|||
*/
|
||||
function getModuleSkinVars($module_srl)
|
||||
{
|
||||
$skin_vars = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_skin_vars:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$skin_vars = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
if($skin_vars === false)
|
||||
$skin_vars = Rhymix\Framework\Cache::get("site_and_module:module_skin_vars:$module_srl");
|
||||
if($skin_vars === null)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->module_srl = $module_srl;
|
||||
|
|
@ -1834,7 +1709,7 @@ class moduleModel extends module
|
|||
$skin_vars[$vars->name] = $vars;
|
||||
}
|
||||
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);
|
||||
Rhymix\Framework\Cache::set("site_and_module:module_skin_vars:$module_srl", $skin_vars, 0, true);
|
||||
}
|
||||
|
||||
return $skin_vars;
|
||||
|
|
@ -1901,7 +1776,6 @@ class moduleModel extends module
|
|||
{
|
||||
if(!$module_info->module_srl) return;
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if(Mobile::isFromMobilePhone())
|
||||
{
|
||||
$skin_vars = $this->getModuleMobileSkinVars($module_info->module_srl);
|
||||
|
|
@ -1927,16 +1801,8 @@ class moduleModel extends module
|
|||
*/
|
||||
function getModuleMobileSkinVars($module_srl)
|
||||
{
|
||||
$skin_vars = false;
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_mobile_skin_vars:'.$module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$skin_vars = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
|
||||
if($skin_vars === false)
|
||||
$skin_vars = Rhymix\Framework\Cache::get("site_and_module:module_mobile_skin_vars:$module_srl");
|
||||
if($skin_vars === null)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->module_srl = $module_srl;
|
||||
|
|
@ -1949,7 +1815,7 @@ class moduleModel extends module
|
|||
$skin_vars[$vars->name] = $vars;
|
||||
}
|
||||
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);
|
||||
Rhymix\Framework\Cache::set("site_and_module:module_mobile_skin_vars:$module_srl", $skin_vars, 0, true);
|
||||
}
|
||||
|
||||
return $skin_vars;
|
||||
|
|
@ -1962,16 +1828,9 @@ class moduleModel extends module
|
|||
function syncMobileSkinInfoToModuleInfo(&$module_info)
|
||||
{
|
||||
if(!$module_info->module_srl) return;
|
||||
$skin_vars = false;
|
||||
// cache controll
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'module_mobile_skin_vars:'.$module_info->module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$skin_vars = $oCacheHandler->get($cache_key);
|
||||
}
|
||||
if($skin_vars === false)
|
||||
|
||||
$skin_vars = Rhymix\Framework\Cache::get('site_and_module:module_mobile_skin_vars:' . $module_info->module_srl);
|
||||
if($skin_vars === null)
|
||||
{
|
||||
$args = new stdClass;
|
||||
$args->module_srl = $module_info->module_srl;
|
||||
|
|
@ -1979,8 +1838,7 @@ class moduleModel extends module
|
|||
if(!$output->toBool()) return;
|
||||
$skin_vars = $output->data;
|
||||
|
||||
//insert in cache
|
||||
if($oCacheHandler->isSupport()) $oCacheHandler->put($cache_key, $skin_vars);
|
||||
Rhymix\Framework\Cache::set('site_and_module:module_mobile_skin_vars:' . $module_info->module_srl, $skin_vars, 0, true);
|
||||
}
|
||||
if(!$skin_vars) return;
|
||||
|
||||
|
|
|
|||
|
|
@ -282,13 +282,7 @@ class pageAdminController extends page
|
|||
}
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'mid_info:' . $module_info->module_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('site_and_module', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
Rhymix\Framework\Cache::delete('site_and_module:mid_info:' . $module_info->module_srl);
|
||||
}
|
||||
|
||||
function procPageAdminArticleDocumentInsert()
|
||||
|
|
|
|||
|
|
@ -402,12 +402,7 @@ class pointAdminController extends point
|
|||
executeQuery('module.deleteModulePartConfig', $args);
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->invalidateGroupKey('site_and_module');
|
||||
}
|
||||
|
||||
Rhymix\Framework\Cache::clearGroup('site_and_module');
|
||||
$this->setMessage('success_updated');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -688,21 +688,7 @@ class pointController extends point
|
|||
$cache_filename = sprintf('%s%d.cache.txt', $cache_path, $member_srl);
|
||||
FileHandler::writeFile($cache_filename, $point);
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object', null, true);
|
||||
if($new_group_list && $del_group_list && $oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'member_groups:' . getNumberingPath($member_srl) . $member_srl . '_0';
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($new_group_list && $del_group_list && $oCacheHandler->isSupport())
|
||||
{
|
||||
$object_key = 'member_info:' . getNumberingPath($member_srl) . $member_srl;
|
||||
$cache_key = $oCacheHandler->getGroupKey('member', $object_key);
|
||||
$oCacheHandler->delete($cache_key);
|
||||
}
|
||||
getController('member')->_clearMemberCache($member_srl);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,6 @@ class widgetController extends widget
|
|||
var $javascript_mode = false;
|
||||
var $layout_javascript_mode = false;
|
||||
|
||||
// Where the cache files are created widget
|
||||
var $cache_path = './files/cache/widget_cache/';
|
||||
|
||||
/**
|
||||
* @brief Initialization
|
||||
*/
|
||||
|
|
@ -343,11 +340,9 @@ class widgetController extends widget
|
|||
{
|
||||
foreach($args as $k => $v) $args->{$k} = urldecode($v);
|
||||
}
|
||||
// If the cache file for each language widget regeneration
|
||||
|
||||
foreach($lang_list as $lang_type => $val)
|
||||
{
|
||||
$cache_file = sprintf('%s%s.%s.cache', $this->cache_path, $sequence, $lang_type);
|
||||
if(!file_exists($cache_file)) continue;
|
||||
$this->getCache($widget, $args, $lang_type, true, $sequence);
|
||||
}
|
||||
}
|
||||
|
|
@ -397,61 +392,20 @@ class widgetController extends widget
|
|||
return $widget_content;
|
||||
}
|
||||
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
$cache_data = Rhymix\Framework\Cache::get('widget_cache:' . $widget_sequence);
|
||||
if ($cache_data)
|
||||
{
|
||||
$key = 'widget_cache:' . $widget_sequence;
|
||||
|
||||
$cache_body = $oCacheHandler->get($key, RX_TIME - $widget_cache);
|
||||
$cache_body = preg_replace('@<\!--#Meta:@', '<!--Meta:', $cache_body);
|
||||
return preg_replace('@<\!--#Meta:@', '<!--Meta:', $cache_data);
|
||||
}
|
||||
|
||||
if($cache_body)
|
||||
{
|
||||
return $cache_body;
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* Cache number and cache values are set so that the cache file should call
|
||||
*/
|
||||
FileHandler::makeDir($this->cache_path);
|
||||
// Wanted cache file
|
||||
$cache_file = sprintf('%s%s.%s.cache', $this->cache_path, $widget_sequence, $lang_type);
|
||||
// If the file exists in the cache, the file validation
|
||||
if(!$ignore_cache && file_exists($cache_file))
|
||||
{
|
||||
$filemtime = filemtime($cache_file);
|
||||
// Should be modified compared to the time of the cache or in the future if creating more than widget.controller.php file a return value of the cache
|
||||
if($filemtime + $widget_cache > $_SERVER['REQUEST_TIME'] && $filemtime > filemtime(_XE_PATH_.'modules/widget/widget.controller.php'))
|
||||
{
|
||||
$cache_body = FileHandler::readFile($cache_file);
|
||||
$cache_body = preg_replace('@<\!--#Meta:@', '<!--Meta:', $cache_body);
|
||||
$oWidget = $this->getWidgetObject($widget);
|
||||
if(!$oWidget || !method_exists($oWidget,'proc')) return;
|
||||
|
||||
return $cache_body;
|
||||
}
|
||||
}
|
||||
// cache update and cache renewal of the file mtime
|
||||
if(!$oCacheHandler->isSupport())
|
||||
{
|
||||
touch($cache_file);
|
||||
}
|
||||
|
||||
$oWidget = $this->getWidgetObject($widget);
|
||||
if(!$oWidget || !method_exists($oWidget,'proc')) return;
|
||||
|
||||
$widget_content = $oWidget->proc($args);
|
||||
$oModuleController = getController('module');
|
||||
$oModuleController->replaceDefinedLangCode($widget_content);
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$oCacheHandler->put($key, $widget_content, $widget_cache);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileHandler::writeFile($cache_file, $widget_content);
|
||||
}
|
||||
}
|
||||
$widget_content = $oWidget->proc($args);
|
||||
$oModuleController = getController('module');
|
||||
$oModuleController->replaceDefinedLangCode($widget_content);
|
||||
|
||||
Rhymix\Framework\Cache::set('widget_cache:' . $widget_sequence, $widget_content, $widget_cache, true);
|
||||
|
||||
return $widget_content;
|
||||
}
|
||||
|
|
@ -525,7 +479,7 @@ class widgetController extends widget
|
|||
if($args->document_srl)
|
||||
{
|
||||
$oDocumentModel = getModel('document');
|
||||
$oDocument = $oDocumentModel->getDocument($args->document_srl);
|
||||
$oDocument = $oDocumentModel->getDocument($args->document_srl, false, false, false);
|
||||
$body = $oDocument->getContent(false,false,false, false);
|
||||
}
|
||||
else
|
||||
|
|
@ -565,7 +519,7 @@ class widgetController extends widget
|
|||
if($args->document_srl)
|
||||
{
|
||||
$oDocumentModel = getModel('document');
|
||||
$oDocument = $oDocumentModel->getDocument($args->document_srl);
|
||||
$oDocument = $oDocumentModel->getDocument($args->document_srl, false, false, false);
|
||||
$body = $oDocument->getContent(false,false,false);
|
||||
}
|
||||
else
|
||||
|
|
@ -810,13 +764,7 @@ class widgetController extends widget
|
|||
|
||||
if($vars->widget_sequence)
|
||||
{
|
||||
$oCacheHandler = CacheHandler::getInstance('object');
|
||||
if($oCacheHandler->isSupport())
|
||||
{
|
||||
$cache_body = $oCacheHandler->delete('widget_cache:' . $vars->widget_sequence);
|
||||
}
|
||||
$cache_file = sprintf('%s%s.%s.cache', $this->cache_path, $vars->widget_sequence, Context::getLangType());
|
||||
FileHandler::removeFile($cache_file);
|
||||
Rhymix\Framework\Cache::delete('widget_cache:' . $vars->widget_sequence);
|
||||
}
|
||||
|
||||
if($vars->widget_cache>0) $vars->widget_sequence = getNextSequence();
|
||||
|
|
|
|||
188
tests/unit/framework/CacheTest.php
Normal file
188
tests/unit/framework/CacheTest.php
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
|
||||
class CacheTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
public function _before()
|
||||
{
|
||||
if (!Rhymix\Framework\Config::get('crypto.authentication_key'))
|
||||
{
|
||||
Rhymix\Framework\Config::set('crypto.authentication_key', Rhymix\Framework\Security::getRandom(64, 'alnum'));
|
||||
}
|
||||
|
||||
$driver = Rhymix\Framework\Cache::init(array('file'));
|
||||
}
|
||||
|
||||
public function _after()
|
||||
{
|
||||
$driver = Rhymix\Framework\Cache::clearAll();
|
||||
}
|
||||
|
||||
public function testInit()
|
||||
{
|
||||
$driver = Rhymix\Framework\Cache::init(array('type' => 'file'));
|
||||
$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
|
||||
|
||||
$driver = Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
|
||||
$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\SQLite);
|
||||
|
||||
$driver = Rhymix\Framework\Cache::init(array());
|
||||
$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\Dummy);
|
||||
}
|
||||
|
||||
public function testGetSupportedDrivers()
|
||||
{
|
||||
$drivers = Rhymix\Framework\Cache::getSupportedDrivers();
|
||||
$this->assertTrue(is_array($drivers));
|
||||
$this->assertContains('dummy', $drivers);
|
||||
$this->assertContains('file', $drivers);
|
||||
$this->assertContains('sqlite', $drivers);
|
||||
}
|
||||
|
||||
public function testGetDriverName()
|
||||
{
|
||||
$driver = Rhymix\Framework\Cache::init(array('type' => 'dummy'));
|
||||
$this->assertEquals('dummy', Rhymix\Framework\Cache::getDriverName());
|
||||
|
||||
$driver = Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
|
||||
$this->assertEquals('sqlite', Rhymix\Framework\Cache::getDriverName());
|
||||
}
|
||||
|
||||
public function testGetDriverInstance()
|
||||
{
|
||||
$driver = Rhymix\Framework\Cache::getDriverInstance('dummy');
|
||||
$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\Dummy);
|
||||
|
||||
$driver = Rhymix\Framework\Cache::getDriverInstance();
|
||||
$this->assertTrue($driver instanceof Rhymix\Framework\Drivers\Cache\File);
|
||||
}
|
||||
|
||||
public function testGetPrefix()
|
||||
{
|
||||
$prefix = Rhymix\Framework\Cache::getPrefix();
|
||||
$this->assertEquals(\RX_VERSION . ':', $prefix);
|
||||
}
|
||||
|
||||
public function testGetSet()
|
||||
{
|
||||
$value = true;
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar1', $value));
|
||||
$this->assertTrue(Rhymix\Framework\Cache::get('foobar1'));
|
||||
|
||||
$value = false;
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar2', $value));
|
||||
$this->assertFalse(Rhymix\Framework\Cache::get('foobar2'));
|
||||
|
||||
$value = 1756234;
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar3', $value));
|
||||
$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar3'));
|
||||
|
||||
$value = 'Rhymix is a PHP CMS.';
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar4', $value));
|
||||
$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar4'));
|
||||
|
||||
$value = array('foo' => 'bar', 'rhy' => 'mix');
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:5', $value));
|
||||
$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar:subkey:5'));
|
||||
|
||||
$value = (object)array('foo' => 'bar', 'rhy' => 'mix');
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:6', $value));
|
||||
$this->assertEquals($value, Rhymix\Framework\Cache::get('foobar:subkey:6'));
|
||||
|
||||
$this->assertNull(Rhymix\Framework\Cache::get('foobar7'));
|
||||
$this->assertNull(Rhymix\Framework\Cache::get('foobar:subkey:8'));
|
||||
}
|
||||
|
||||
public function testDeleteAndExists()
|
||||
{
|
||||
Rhymix\Framework\Cache::set('foo', 'FOO');
|
||||
Rhymix\Framework\Cache::set('bar', 'BAR');
|
||||
|
||||
$this->assertTrue(Rhymix\Framework\Cache::delete('foo'));
|
||||
$this->assertFalse(Rhymix\Framework\Cache::delete('foo'));
|
||||
$this->assertFalse(Rhymix\Framework\Cache::exists('foo'));
|
||||
$this->assertTrue(Rhymix\Framework\Cache::exists('bar'));
|
||||
}
|
||||
|
||||
public function testIncrDecr()
|
||||
{
|
||||
Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
|
||||
Rhymix\Framework\Cache::set('foo', 'foo');
|
||||
Rhymix\Framework\Cache::set('bar', 42);
|
||||
$prefix = Rhymix\Framework\Cache::getPrefix();
|
||||
|
||||
$this->assertEquals(1, Rhymix\Framework\Cache::getDriverInstance()->incr($prefix . 'foo', 1));
|
||||
$this->assertEquals(45, Rhymix\Framework\Cache::getDriverInstance()->incr($prefix . 'bar', 3));
|
||||
$this->assertEquals(-1, Rhymix\Framework\Cache::getDriverInstance()->decr($prefix . 'foo', 2));
|
||||
$this->assertEquals(49, Rhymix\Framework\Cache::getDriverInstance()->decr($prefix . 'bar', -4));
|
||||
}
|
||||
|
||||
public function testClearAll()
|
||||
{
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foo', 'foo'));
|
||||
$this->assertTrue(Rhymix\Framework\Cache::exists('foo'));
|
||||
$this->assertTrue(Rhymix\Framework\Cache::clearAll());
|
||||
$this->assertFalse(Rhymix\Framework\Cache::exists('foo'));
|
||||
}
|
||||
|
||||
public function testCacheGroups()
|
||||
{
|
||||
Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
|
||||
$prefix = Rhymix\Framework\Cache::getPrefix();
|
||||
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:1234', 'rhymix'));
|
||||
$this->assertTrue(Rhymix\Framework\Cache::exists('foobar:subkey:1234'));
|
||||
$this->assertEquals('rhymix', Rhymix\Framework\Cache::get('foobar:subkey:1234'));
|
||||
$this->assertEquals('rhymix', Rhymix\Framework\Cache::getDriverInstance()->get($prefix . 'foobar#0:subkey:1234'));
|
||||
$this->assertEquals(0, Rhymix\Framework\Cache::getGroupVersion('foobar'));
|
||||
|
||||
$this->assertTrue(Rhymix\Framework\Cache::clearGroup('foobar'));
|
||||
$this->assertFalse(Rhymix\Framework\Cache::exists('foobar:subkey:1234'));
|
||||
$this->assertTrue(Rhymix\Framework\Cache::set('foobar:subkey:1234', 'rhymix'));
|
||||
$this->assertEquals('rhymix', Rhymix\Framework\Cache::getDriverInstance()->get($prefix . 'foobar#1:subkey:1234'));
|
||||
$this->assertEquals(1, Rhymix\Framework\Cache::getGroupVersion('foobar'));
|
||||
}
|
||||
|
||||
public function testGetRealKey()
|
||||
{
|
||||
Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
|
||||
$prefix = Rhymix\Framework\Cache::getPrefix();
|
||||
|
||||
$this->assertEquals($prefix . 'foo', Rhymix\Framework\Cache::getRealKey('foo'));
|
||||
$this->assertEquals($prefix . 'bar#0:2016', Rhymix\Framework\Cache::getRealKey('bar:2016'));
|
||||
Rhymix\Framework\Cache::clearGroup('bar');
|
||||
$this->assertEquals($prefix . 'bar#1:2016', Rhymix\Framework\Cache::getRealKey('bar:2016'));
|
||||
Rhymix\Framework\Cache::clearGroup('bar');
|
||||
$this->assertEquals($prefix . 'bar#2:2016', Rhymix\Framework\Cache::getRealKey('bar:2016'));
|
||||
}
|
||||
|
||||
public function testCompatibility()
|
||||
{
|
||||
Rhymix\Framework\Cache::init(array('type' => 'sqlite'));
|
||||
$ch = \CacheHandler::getInstance();
|
||||
$this->assertTrue($ch instanceof \CacheHandler);
|
||||
$this->assertTrue($ch->isSupport());
|
||||
|
||||
$this->assertEquals('rhymix', $ch->getCacheKey('rhymix'));
|
||||
$this->assertEquals('rhymix:123:456', $ch->getCacheKey('rhymix:123:456'));
|
||||
|
||||
$this->assertTrue($ch->put('rhymix', 'foo bar buzz'));
|
||||
$this->assertEquals('foo bar buzz', $ch->get('rhymix'));
|
||||
$this->assertTrue($ch->isValid('rhymix'));
|
||||
$this->assertTrue($ch->delete('rhymix'));
|
||||
$this->assertFalse($ch->get('rhymix'));
|
||||
$this->assertFalse($ch->isValid('rhymix'));
|
||||
|
||||
$this->assertEquals('rhymix:123:456', $ch->getGroupKey('rhymix', '123:456'));
|
||||
$this->assertTrue($ch->put('rhymix:123:456', 'rhymix rules!'));
|
||||
$this->assertEquals('rhymix rules!', $ch->get('rhymix:123:456'));
|
||||
$this->assertEquals(0, Rhymix\Framework\Cache::getGroupVersion('rhymix'));
|
||||
|
||||
$this->assertTrue($ch->invalidateGroupKey('rhymix'));
|
||||
$this->assertTrue($ch->put('rhymix:123:456', 'rhymix rules!'));
|
||||
$this->assertEquals('rhymix rules!', $ch->get('rhymix:123:456'));
|
||||
$this->assertEquals(1, Rhymix\Framework\Cache::getGroupVersion('rhymix'));
|
||||
|
||||
$this->assertTrue($ch->truncate());
|
||||
$this->assertFalse($ch->get('rhymix:123:456'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue