mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-16 09:49:54 +09:00
merge from 1.7.3.5(r13153:r13167)
git-svn-id: http://xe-core.googlecode.com/svn/trunk@13168 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
cc47d2b247
commit
2d3f149b5a
2042 changed files with 129266 additions and 126243 deletions
80
classes/cache/CacheApc.class.php
vendored
80
classes/cache/CacheApc.class.php
vendored
|
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Cache class for APC
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
**/
|
||||
class CacheApc extends CacheBase {
|
||||
* */
|
||||
class CacheApc extends CacheBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
|
|
@ -17,8 +20,10 @@ class CacheApc extends CacheBase {
|
|||
* @param void $opt Not used
|
||||
* @return CacheApc instance of CacheApc
|
||||
*/
|
||||
function getInstance($opt=null){
|
||||
if(!$GLOBALS['__CacheApc__']) {
|
||||
function getInstance($opt = null)
|
||||
{
|
||||
if(!$GLOBALS['__CacheApc__'])
|
||||
{
|
||||
$GLOBALS['__CacheApc__'] = new CacheApc();
|
||||
}
|
||||
return $GLOBALS['__CacheApc__'];
|
||||
|
|
@ -29,7 +34,9 @@ class CacheApc extends CacheBase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function CacheApc(){
|
||||
function CacheApc()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,7 +44,8 @@ class CacheApc extends CacheBase {
|
|||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
return function_exists('apc_add');
|
||||
}
|
||||
|
||||
|
|
@ -47,13 +55,18 @@ class CacheApc extends CacheBase {
|
|||
* @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.
|
||||
* 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(time(), $buff), $valid_time);
|
||||
function put($key, $buff, $valid_time = 0)
|
||||
{
|
||||
if($valid_time == 0)
|
||||
{
|
||||
$valid_time = $this->valid_time;
|
||||
}
|
||||
|
||||
return apc_store(md5(_XE_PATH_ . $key), array(time(), $buff), $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,20 +74,25 @@ class CacheApc extends CacheBase {
|
|||
*
|
||||
* @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.
|
||||
* 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);
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
if(!$success || !is_array($obj)) return false;
|
||||
if(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -83,15 +101,20 @@ class CacheApc extends CacheBase {
|
|||
*
|
||||
* @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.
|
||||
* 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);
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
if(!$success || !is_array($obj)) return false;
|
||||
if(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -105,8 +128,9 @@ class CacheApc extends CacheBase {
|
|||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
$this->put($_key,null,1);
|
||||
function _delete($_key)
|
||||
{
|
||||
$this->put($_key, null, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,7 +139,8 @@ class CacheApc extends CacheBase {
|
|||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
function delete($key)
|
||||
{
|
||||
$this->_delete($key);
|
||||
}
|
||||
|
||||
|
|
@ -124,10 +149,11 @@ class CacheApc extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
return apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheApc.class.php */
|
||||
/* Location: ./classes/cache/CacheApc.class.php */
|
||||
|
|
|
|||
67
classes/cache/CacheFile.class.php
vendored
67
classes/cache/CacheFile.class.php
vendored
|
|
@ -1,12 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Cache class for file
|
||||
*
|
||||
* Filedisk Cache Handler
|
||||
*
|
||||
* @author Arnia Software (xe_dev@arnia.ro)
|
||||
**/
|
||||
class CacheFile extends CacheBase {
|
||||
*/
|
||||
class CacheFile extends CacheBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
|
|
@ -18,14 +21,16 @@ class CacheFile extends CacheBase {
|
|||
* @var string
|
||||
*/
|
||||
var $cache_dir = 'files/cache/store/';
|
||||
|
||||
|
||||
/**
|
||||
* Get instance of CacheFile
|
||||
*
|
||||
* @return CacheFile instance of CacheFile
|
||||
*/
|
||||
function getInstance(){
|
||||
if(!$GLOBALS['__CacheFile__']) {
|
||||
function getInstance()
|
||||
{
|
||||
if(!$GLOBALS['__CacheFile__'])
|
||||
{
|
||||
$GLOBALS['__CacheFile__'] = new CacheFile();
|
||||
}
|
||||
return $GLOBALS['__CacheFile__'];
|
||||
|
|
@ -36,9 +41,13 @@ class CacheFile extends CacheBase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function CacheFile(){
|
||||
function CacheFile()
|
||||
{
|
||||
$this->cache_dir = _XE_PATH_ . $this->cache_dir;
|
||||
if(!is_dir($this->cache_dir)) FileHandler::makeDir($this->cache_dir);
|
||||
if(!is_dir($this->cache_dir))
|
||||
{
|
||||
FileHandler::makeDir($this->cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -47,16 +56,18 @@ class CacheFile extends CacheBase {
|
|||
* @param string $key The key that will be associated with the item.
|
||||
* @return string Returns cache file path
|
||||
*/
|
||||
function getCacheFileName($key){
|
||||
function getCacheFileName($key)
|
||||
{
|
||||
return $this->cache_dir . str_replace(':', '_', $key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return whether support or not support cache
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -68,8 +79,9 @@ class CacheFile extends CacheBase {
|
|||
* @param int $valid_time Not used
|
||||
* @return void
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
function put($key, $obj, $valid_time = 0)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
$text = serialize($obj);
|
||||
FileHandler::writeFile($cache_file, $text);
|
||||
}
|
||||
|
|
@ -81,10 +93,14 @@ class CacheFile extends CacheBase {
|
|||
* @param int $modified_time Not used
|
||||
* @return bool Return true on valid or false on invalid.
|
||||
*/
|
||||
function isValid($key, $modified_time = 0) {
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
if(file_exists($cache_file)) return true;
|
||||
|
||||
if(file_exists($cache_file))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -95,11 +111,15 @@ class CacheFile extends CacheBase {
|
|||
* @param int $modified_time Not used
|
||||
* @return false|mixed Return false on failure. Return the string associated with the $key on success.
|
||||
*/
|
||||
function get($key, $modified_time = 0) {
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
$content = FileHandler::readFile($cache_file);
|
||||
if(!$content) return false;
|
||||
|
||||
if(!$content)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return unserialize($content);
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +129,8 @@ class CacheFile extends CacheBase {
|
|||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
function _delete($_key)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($_key);
|
||||
FileHandler::removeFile($cache_file);
|
||||
}
|
||||
|
|
@ -120,7 +141,8 @@ class CacheFile extends CacheBase {
|
|||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
function delete($key)
|
||||
{
|
||||
$this->_delete($key);
|
||||
}
|
||||
|
||||
|
|
@ -129,10 +151,11 @@ class CacheFile extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
FileHandler::removeFilesInDir($this->cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheFile.class.php */
|
||||
/* Location: ./classes/cache/CacheFile.class.php */
|
||||
|
|
|
|||
180
classes/cache/CacheHandler.class.php
vendored
180
classes/cache/CacheHandler.class.php
vendored
|
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* CacheHandler
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
**/
|
||||
class CacheHandler extends Handler {
|
||||
*/
|
||||
class CacheHandler extends Handler
|
||||
{
|
||||
|
||||
/**
|
||||
* instance of cache handler
|
||||
* @var CacheBase
|
||||
|
|
@ -25,9 +28,11 @@ class CacheHandler extends Handler {
|
|||
* @param boolean $always_use_file If set true, use a file cache always
|
||||
* @return CacheHandler
|
||||
*/
|
||||
function &getInstance($target = 'object', $info = null, $always_use_file = false) {
|
||||
function &getInstance($target = 'object', $info = null, $always_use_file = false)
|
||||
{
|
||||
$cache_handler_key = $target . ($always_use_file ? '_file' : '');
|
||||
if(!$GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key]) {
|
||||
if(!$GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key])
|
||||
{
|
||||
$GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key] = new CacheHandler($target, $info, $always_use_file);
|
||||
}
|
||||
return $GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key];
|
||||
|
|
@ -44,34 +49,67 @@ class CacheHandler extends Handler {
|
|||
* @param boolean $always_use_file If set true, use a file cache always
|
||||
* @return CacheHandler
|
||||
*/
|
||||
function CacheHandler($target, $info = null, $always_use_file = false) {
|
||||
if(!$info) $info = Context::getDBInfo();
|
||||
if($info){
|
||||
if($target == 'object'){
|
||||
if($info->use_object_cache =='apc') $type = 'apc';
|
||||
else if(substr($info->use_object_cache,0,8)=='memcache'){
|
||||
function CacheHandler($target, $info = null, $always_use_file = false)
|
||||
{
|
||||
if(!$info)
|
||||
{
|
||||
$info = Context::getDBInfo();
|
||||
}
|
||||
|
||||
if($info)
|
||||
{
|
||||
if($target == 'object')
|
||||
{
|
||||
if($info->use_object_cache == 'apc')
|
||||
{
|
||||
$type = 'apc';
|
||||
}
|
||||
else if(substr($info->use_object_cache, 0, 8) == 'memcache')
|
||||
{
|
||||
$type = 'memcache';
|
||||
$url = $info->use_object_cache;
|
||||
} else if($info->use_object_cache == 'wincache') $type = 'wincache';
|
||||
else if($info->use_object_cache =='file') $type = 'file';
|
||||
else if($always_use_file) $type = 'file';
|
||||
}else if($target == 'template'){
|
||||
if($info->use_template_cache =='apc') $type = 'apc';
|
||||
else if(substr($info->use_template_cache,0,8)=='memcache'){
|
||||
}
|
||||
else if($info->use_object_cache == 'wincache')
|
||||
{
|
||||
$type = 'wincache';
|
||||
}
|
||||
else if($info->use_object_cache == 'file')
|
||||
{
|
||||
$type = 'file';
|
||||
}
|
||||
else if($always_use_file)
|
||||
{
|
||||
$type = 'file';
|
||||
}
|
||||
}
|
||||
else if($target == 'template')
|
||||
{
|
||||
if($info->use_template_cache == 'apc')
|
||||
{
|
||||
$type = 'apc';
|
||||
}
|
||||
else if(substr($info->use_template_cache, 0, 8) == 'memcache')
|
||||
{
|
||||
$type = 'memcache';
|
||||
$url = $info->use_template_cache;
|
||||
} else if($info->use_template_cache == 'wincache') $type = 'wincache';
|
||||
}
|
||||
else if($info->use_template_cache == 'wincache')
|
||||
{
|
||||
$type = 'wincache';
|
||||
}
|
||||
}
|
||||
|
||||
if($type){
|
||||
if($type)
|
||||
{
|
||||
$class = 'Cache' . ucfirst($type);
|
||||
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
|
||||
$this->handler = call_user_func(array($class,'getInstance'), $url);
|
||||
$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->handler = call_user_func(array($class, 'getInstance'), $url);
|
||||
$this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
|
||||
if(!$this->keyGroupVersions)
|
||||
{
|
||||
$this->keyGroupVersions = array();
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,8 +119,12 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isSupport(){
|
||||
if($this->handler && $this->handler->isSupport()) return true;
|
||||
function isSupport()
|
||||
{
|
||||
if($this->handler && $this->handler->isSupport())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -91,11 +133,15 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* @param string $key Cache key
|
||||
* @param int $modified_time Unix time of data modified.
|
||||
* If stored time is older then modified time, return false.
|
||||
* 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){
|
||||
if(!$this->handler) return false;
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
if(!$this->handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->handler->get($key, $modified_time);
|
||||
}
|
||||
|
||||
|
|
@ -105,12 +151,16 @@ class CacheHandler extends Handler {
|
|||
* @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.
|
||||
* 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.
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
if(!$this->handler) return false;
|
||||
function put($key, $obj, $valid_time = 0)
|
||||
{
|
||||
if(!$this->handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->handler->put($key, $obj, $valid_time);
|
||||
}
|
||||
|
||||
|
|
@ -120,8 +170,12 @@ class CacheHandler extends Handler {
|
|||
* @param string $key Cache key
|
||||
* @return void
|
||||
*/
|
||||
function delete($key){
|
||||
if(!$this->handler) return false;
|
||||
function delete($key)
|
||||
{
|
||||
if(!$this->handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->handler->delete($key);
|
||||
}
|
||||
|
||||
|
|
@ -130,11 +184,15 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* @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.
|
||||
* 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){
|
||||
if(!$this->handler) return false;
|
||||
function isValid($key, $modified_time)
|
||||
{
|
||||
if(!$this->handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->handler->isValid($key, $modified_time);
|
||||
}
|
||||
|
||||
|
|
@ -143,8 +201,12 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
function truncate(){
|
||||
if(!$this->handler) return false;
|
||||
function truncate()
|
||||
{
|
||||
if(!$this->handler)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $this->handler->truncate();
|
||||
}
|
||||
|
||||
|
|
@ -164,8 +226,10 @@ class CacheHandler extends Handler {
|
|||
* @param string $key Cache key
|
||||
* @return string
|
||||
*/
|
||||
function getGroupKey($keyGroupName, $key){
|
||||
if(!$this->keyGroupVersions[$keyGroupName]){
|
||||
function getGroupKey($keyGroupName, $key)
|
||||
{
|
||||
if(!$this->keyGroupVersions[$keyGroupName])
|
||||
{
|
||||
$this->keyGroupVersions[$keyGroupName] = 1;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
|
|
@ -179,10 +243,12 @@ class CacheHandler extends Handler {
|
|||
* @param string $keyGroupName Group name
|
||||
* @return void
|
||||
*/
|
||||
function invalidateGroupKey($keyGroupName){
|
||||
function invalidateGroupKey($keyGroupName)
|
||||
{
|
||||
$this->keyGroupVersions[$keyGroupName]++;
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -190,17 +256,19 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
*/
|
||||
class CacheBase{
|
||||
class CacheBase
|
||||
{
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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){
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -210,11 +278,12 @@ class CacheBase{
|
|||
* @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.
|
||||
* 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.
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
function put($key, $obj, $valid_time = 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -223,10 +292,11 @@ class CacheBase{
|
|||
*
|
||||
* @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.
|
||||
* 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){
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +305,8 @@ class CacheBase{
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -244,10 +315,11 @@ class CacheBase{
|
|||
*
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
function truncate(){
|
||||
function truncate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheHandler.class.php */
|
||||
/* Location: ./classes/cache/CacheHandler.class.php */
|
||||
|
|
|
|||
90
classes/cache/CacheMemcache.class.php
vendored
90
classes/cache/CacheMemcache.class.php
vendored
|
|
@ -1,10 +1,13 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Cache class for memcache
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
**/
|
||||
class CacheMemcache extends CacheBase {
|
||||
*/
|
||||
class CacheMemcache extends CacheBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
|
|
@ -23,8 +26,10 @@ class CacheMemcache extends CacheBase {
|
|||
* @param string $url url of memcache
|
||||
* @return CacheMemcache instance of CacheMemcache
|
||||
*/
|
||||
function getInstance($url){
|
||||
if(!$GLOBALS['__CacheMemcache__']) {
|
||||
function getInstance($url)
|
||||
{
|
||||
if(!$GLOBALS['__CacheMemcache__'])
|
||||
{
|
||||
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
|
||||
}
|
||||
return $GLOBALS['__CacheMemcache__'];
|
||||
|
|
@ -37,12 +42,14 @@ class CacheMemcache extends CacheBase {
|
|||
* @param string $url url of memcache
|
||||
* @return void
|
||||
*/
|
||||
function CacheMemcache($url){
|
||||
function CacheMemcache($url)
|
||||
{
|
||||
//$config['url'] = array('memcache://localhost:11211');
|
||||
$config['url'] = is_array($url)?$url:array($url);
|
||||
$config['url'] = is_array($url) ? $url : array($url);
|
||||
$this->Memcache = new Memcache;
|
||||
|
||||
foreach($config['url'] as $url) {
|
||||
foreach($config['url'] as $url)
|
||||
{
|
||||
$info = parse_url($url);
|
||||
$this->Memcache->addServer($info['host'], $info['port']);
|
||||
}
|
||||
|
|
@ -53,11 +60,18 @@ class CacheMemcache extends CacheBase {
|
|||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport(){
|
||||
if($GLOBALS['XE_MEMCACHE_SUPPORT']) return true;
|
||||
if($this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1)) {
|
||||
function isSupport()
|
||||
{
|
||||
if($GLOBALS['XE_MEMCACHE_SUPPORT'])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if($this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1))
|
||||
{
|
||||
$GLOBALS['XE_MEMCACHE_SUPPORT'] = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$GLOBALS['XE_MEMCACHE_SUPPORT'] = false;
|
||||
}
|
||||
return $GLOBALS['XE_MEMCACHE_SUPPORT'];
|
||||
|
|
@ -69,8 +83,9 @@ class CacheMemcache extends CacheBase {
|
|||
* @param string $key Cache key
|
||||
* @return string Return unique key
|
||||
*/
|
||||
function getKey($key){
|
||||
return md5(_XE_PATH_.$key);
|
||||
function getKey($key)
|
||||
{
|
||||
return md5(_XE_PATH_ . $key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,12 +101,16 @@ class CacheMemcache extends CacheBase {
|
|||
* @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.
|
||||
* 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.
|
||||
*/
|
||||
function put($key, $buff, $valid_time = 0){
|
||||
if($valid_time == 0) $valid_time = $this->valid_time;
|
||||
function put($key, $buff, $valid_time = 0)
|
||||
{
|
||||
if($valid_time == 0)
|
||||
{
|
||||
$valid_time = $this->valid_time;
|
||||
}
|
||||
|
||||
return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
|
||||
}
|
||||
|
|
@ -101,17 +120,22 @@ class CacheMemcache extends CacheBase {
|
|||
*
|
||||
* @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.
|
||||
* 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) {
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$_key = $this->getKey($key);
|
||||
|
||||
$obj = $this->Memcache->get($_key);
|
||||
if(!$obj || !is_array($obj)) return false;
|
||||
if(!$obj || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -126,15 +150,20 @@ class CacheMemcache extends CacheBase {
|
|||
*
|
||||
* @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.
|
||||
* 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) {
|
||||
function get($key, $modified_time = 0)
|
||||
{
|
||||
$_key = $this->getKey($key);
|
||||
$obj = $this->Memcache->get($_key);
|
||||
if(!$obj || !is_array($obj)) return false;
|
||||
if(!$obj || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -152,7 +181,8 @@ class CacheMemcache extends CacheBase {
|
|||
* @param string $key The key associated with the item to delete.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
function delete($key)
|
||||
{
|
||||
$_key = $this->getKey($key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
|
@ -164,7 +194,8 @@ class CacheMemcache extends CacheBase {
|
|||
* @param string $_key The key associated with the item to delete.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
function _delete($_key)
|
||||
{
|
||||
$this->Memcache->delete($_key);
|
||||
}
|
||||
|
||||
|
|
@ -177,10 +208,11 @@ class CacheMemcache extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
return $this->Memcache->flush();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheMemcache.class.php */
|
||||
/* Location: ./classes/cache/CacheMemcache.class.php */
|
||||
|
|
|
|||
81
classes/cache/CacheWincache.class.php
vendored
81
classes/cache/CacheWincache.class.php
vendored
|
|
@ -1,12 +1,15 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Cache class for Wincache
|
||||
*
|
||||
* Wincache Handler
|
||||
*
|
||||
* @author Arnia (support@xpressengine.org)
|
||||
**/
|
||||
class CacheWincache extends CacheBase {
|
||||
*/
|
||||
class CacheWincache extends CacheBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
|
|
@ -19,8 +22,10 @@ class CacheWincache extends CacheBase {
|
|||
* @param void $opt Not used
|
||||
* @return CacheWincache instance of CacheWincache
|
||||
*/
|
||||
function getInstance($opt=null){
|
||||
if(!$GLOBALS['__CacheWincache__']) {
|
||||
function getInstance($opt = null)
|
||||
{
|
||||
if(!$GLOBALS['__CacheWincache__'])
|
||||
{
|
||||
$GLOBALS['__CacheWincache__'] = new CacheWincache();
|
||||
}
|
||||
return $GLOBALS['__CacheWincache__'];
|
||||
|
|
@ -31,7 +36,9 @@ class CacheWincache extends CacheBase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function CacheWincache(){
|
||||
function CacheWincache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -39,7 +46,8 @@ class CacheWincache extends CacheBase {
|
|||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
return function_exists('wincache_ucache_set');
|
||||
}
|
||||
|
||||
|
|
@ -47,16 +55,20 @@ class CacheWincache extends CacheBase {
|
|||
* 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.
|
||||
* 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.
|
||||
* 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(time(), $buff), $valid_time);
|
||||
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(time(), $buff), $valid_time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,20 +76,25 @@ class CacheWincache extends CacheBase {
|
|||
*
|
||||
* @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.
|
||||
* 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);
|
||||
function isValid($key, $modified_time = 0)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$obj = wincache_ucache_get($_key, $success);
|
||||
if(!$success || !is_array($obj)) return false;
|
||||
if(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -86,15 +103,20 @@ class CacheWincache extends CacheBase {
|
|||
*
|
||||
* @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.
|
||||
* 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);
|
||||
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(!$success || !is_array($obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -108,7 +130,8 @@ class CacheWincache extends CacheBase {
|
|||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
function _delete($_key)
|
||||
{
|
||||
wincache_ucache_delete($_key);
|
||||
}
|
||||
|
||||
|
|
@ -118,8 +141,9 @@ class CacheWincache extends CacheBase {
|
|||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
function delete($key)
|
||||
{
|
||||
$_key = md5(_XE_PATH_ . $key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
||||
|
|
@ -128,10 +152,11 @@ class CacheWincache extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
return wincache_ucache_clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* End of file CacheWincache.class.php */
|
||||
/* Location: ./classes/cache/CacheWincache.class.php */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue