issue 2662 coding convention fix (in classes)

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12144 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
ovclas 2012-11-07 06:06:18 +00:00
parent f9fbd4a307
commit cc1d9775ef
7 changed files with 186 additions and 94 deletions

View file

@ -11,4 +11,4 @@ if($called_position == 'after_module_proc' && Context::getResponseMethod()!="XML
Context::loadFile(array('./addons/autolink/autolink.js', 'body', '', null), true); Context::loadFile(array('./addons/autolink/autolink.js', 'body', '', null), true);
} }
/* End of file autolink.addon.php */ /* End of file autolink.addon.php */
/* Location: .//addons/autolink/autolink.addon.php */ /* Location: ./addons/autolink/autolink.addon.php */

View file

@ -1,2 +1,5 @@
<?php <?php
header('Location: ' . preg_replace('/admin\/|admin/', 'index.php?module=admin', $_SERVER['REQUEST_URI'])); header('Location: ' . preg_replace('/admin\/|admin/', 'index.php?module=admin', $_SERVER['REQUEST_URI']));
/* End of file index.php */
/* Location: ./admin/index.php */

View file

@ -1,10 +1,14 @@
<?php <?php
include '../handler/Handler.class.php';
include './CacheHandler.class.php';
/** /**
* Cache class for APC * Cache class for APC
* *
* @author NHN (developer@xpressengine.com) * @author NHN (developer@xpressengine.com)
**/ **/
class CacheApc extends CacheBase { class CacheApc extends CacheBase
{
/** /**
* Default valid time * Default valid time
* @var int * @var int
@ -17,8 +21,10 @@ class CacheApc extends CacheBase {
* @param void $opt Not used * @param void $opt Not used
* @return CacheApc instance of CacheApc * @return CacheApc instance of CacheApc
*/ */
function getInstance($opt=null){ function getInstance($opt=null)
if(!$GLOBALS['__CacheApc__']) { {
if(!$GLOBALS['__CacheApc__'])
{
$GLOBALS['__CacheApc__'] = new CacheApc(); $GLOBALS['__CacheApc__'] = new CacheApc();
} }
return $GLOBALS['__CacheApc__']; return $GLOBALS['__CacheApc__'];
@ -29,7 +35,8 @@ class CacheApc extends CacheBase {
* *
* @return void * @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 * @return bool Return true on support or false on not support
*/ */
function isSupport(){ function isSupport()
{
return function_exists('apc_add'); return function_exists('apc_add');
} }
@ -51,7 +59,8 @@ class CacheApc extends CacheBase {
* If no ttl is supplied, use the default valid time CacheApc::valid_time. * If no ttl is supplied, use the default valid time CacheApc::valid_time.
* @return bool Returns true on success or false on failure. * @return bool Returns true on success or false on failure.
*/ */
function put($key, $buff, $valid_time = 0){ function put($key, $buff, $valid_time = 0)
{
if($valid_time == 0) $valid_time = $this->valid_time; if($valid_time == 0) $valid_time = $this->valid_time;
return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time); return apc_store(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
} }
@ -64,13 +73,15 @@ class CacheApc extends CacheBase {
* 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. * @return bool Return true on valid or false on invalid.
*/ */
function isValid($key, $modified_time = 0) { function isValid($key, $modified_time = 0)
{
$_key = md5(_XE_PATH_.$key); $_key = md5(_XE_PATH_.$key);
$obj = apc_fetch($_key, $success); $obj = apc_fetch($_key, $success);
if(!$success || !is_array($obj)) return false; if(!$success || !is_array($obj)) return false;
unset($obj[1]); unset($obj[1]);
if($modified_time > 0 && $modified_time > $obj[0]) { if($modified_time > 0 && $modified_time > $obj[0])
{
$this->_delete($_key); $this->_delete($_key);
return false; return false;
} }
@ -86,12 +97,14 @@ class CacheApc extends CacheBase {
* 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. * @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 = md5(_XE_PATH_.$key); $_key = md5(_XE_PATH_.$key);
$obj = apc_fetch($_key, $success); $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); $this->_delete($_key);
return false; return false;
} }
@ -105,7 +118,8 @@ class CacheApc extends CacheBase {
* @param string $_key Used to store the value. * @param string $_key Used to store the value.
* @return void * @return void
*/ */
function _delete($_key) { function _delete($_key)
{
$this->put($_key,null,1); $this->put($_key,null,1);
} }
@ -115,7 +129,8 @@ class CacheApc extends CacheBase {
* @param string $key Used to store the value. * @param string $key Used to store the value.
* @return void * @return void
*/ */
function delete($key) { function delete($key)
{
$this->_delete($key); $this->_delete($key);
} }
@ -124,7 +139,8 @@ class CacheApc extends CacheBase {
* *
* @return bool Returns true on success or false on failure. * @return bool Returns true on success or false on failure.
*/ */
function truncate() { function truncate()
{
return apc_clear_cache('user'); return apc_clear_cache('user');
} }
} }

View file

@ -1,12 +1,16 @@
<?php <?php
include '../handler/Handler.class.php';
include './CacheHandler.class.php';
/** /**
* Cache class for file * Cache class for file
* *
* Filedisk Cache Handler * Filedisk Cache Handler
* *
* @author Arnia Software (xe_dev@arnia.ro) * @author Arnia Software (xe_dev@arnia.ro)
**/ */
class CacheFile extends CacheBase { class CacheFile extends CacheBase
{
/** /**
* Default valid time * Default valid time
* @var int * @var int
@ -24,7 +28,8 @@ class CacheFile extends CacheBase {
* *
* @return CacheFile instance of CacheFile * @return CacheFile instance of CacheFile
*/ */
function getInstance(){ function getInstance()
{
if(!$GLOBALS['__CacheFile__']) { if(!$GLOBALS['__CacheFile__']) {
$GLOBALS['__CacheFile__'] = new CacheFile(); $GLOBALS['__CacheFile__'] = new CacheFile();
} }
@ -36,7 +41,8 @@ class CacheFile extends CacheBase {
* *
* @return void * @return void
*/ */
function CacheFile(){ function CacheFile()
{
$this->cache_dir = _XE_PATH_ . $this->cache_dir; $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,7 +53,8 @@ class CacheFile extends CacheBase {
* @param string $key The key that will be associated with the item. * @param string $key The key that will be associated with the item.
* @return string Returns cache file path * @return string Returns cache file path
*/ */
function getCacheFileName($key){ function getCacheFileName($key)
{
return $this->cache_dir . str_replace(':', '_', $key); return $this->cache_dir . str_replace(':', '_', $key);
} }
@ -56,7 +63,8 @@ class CacheFile extends CacheBase {
* *
* @return true * @return true
*/ */
function isSupport(){ function isSupport()
{
return true; return true;
} }
@ -68,7 +76,8 @@ class CacheFile extends CacheBase {
* @param int $valid_time Not used * @param int $valid_time Not used
* @return void * @return void
*/ */
function put($key, $obj, $valid_time = 0){ function put($key, $obj, $valid_time = 0)
{
$cache_file = $this->getCacheFileName($key); $cache_file = $this->getCacheFileName($key);
$text = serialize($obj); $text = serialize($obj);
FileHandler::writeFile($cache_file, $text); FileHandler::writeFile($cache_file, $text);
@ -81,7 +90,8 @@ class CacheFile extends CacheBase {
* @param int $modified_time Not used * @param int $modified_time Not used
* @return bool Return true on valid or false on invalid. * @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); $cache_file = $this->getCacheFileName($key);
if(file_exists($cache_file)) return true; if(file_exists($cache_file)) return true;
@ -95,7 +105,8 @@ class CacheFile extends CacheBase {
* @param int $modified_time Not used * @param int $modified_time Not used
* @return false|mixed Return false on failure. Return the string associated with the $key on success. * @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); $cache_file = $this->getCacheFileName($key);
$content = FileHandler::readFile($cache_file); $content = FileHandler::readFile($cache_file);
if(!$content) return false; if(!$content) return false;
@ -109,7 +120,8 @@ class CacheFile extends CacheBase {
* @param string $_key Used to store the value. * @param string $_key Used to store the value.
* @return void * @return void
*/ */
function _delete($_key) { function _delete($_key)
{
$cache_file = $this->getCacheFileName($_key); $cache_file = $this->getCacheFileName($_key);
FileHandler::removeFile($cache_file); FileHandler::removeFile($cache_file);
} }
@ -120,7 +132,8 @@ class CacheFile extends CacheBase {
* @param string $key Used to store the value. * @param string $key Used to store the value.
* @return void * @return void
*/ */
function delete($key) { function delete($key)
{
$this->_delete($key); $this->_delete($key);
} }
@ -129,7 +142,8 @@ class CacheFile extends CacheBase {
* *
* @return bool Returns true on success or false on failure. * @return bool Returns true on success or false on failure.
*/ */
function truncate() { function truncate()
{
FileHandler::removeFilesInDir($this->cache_dir); FileHandler::removeFilesInDir($this->cache_dir);
} }
} }

View file

@ -3,8 +3,9 @@
* CacheHandler * CacheHandler
* *
* @author NHN (developer@xpressengine.com) * @author NHN (developer@xpressengine.com)
**/ */
class CacheHandler extends Handler { class CacheHandler extends Handler
{
/** /**
* instance of cache handler * instance of cache handler
* @var CacheBase * @var CacheBase
@ -25,9 +26,11 @@ class CacheHandler extends Handler {
* @param boolean $always_use_file If set true, use a file cache always * @param boolean $always_use_file If set true, use a file cache always
* @return CacheHandler * @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' : ''); $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); $GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key] = new CacheHandler($target, $info, $always_use_file);
} }
return $GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key]; return $GLOBALS['__XE_CACHE_HANDLER__'][$cache_handler_key];
@ -44,31 +47,42 @@ class CacheHandler extends Handler {
* @param boolean $always_use_file If set true, use a file cache always * @param boolean $always_use_file If set true, use a file cache always
* @return CacheHandler * @return CacheHandler
*/ */
function CacheHandler($target, $info = null, $always_use_file = false) { function CacheHandler($target, $info = null, $always_use_file = false)
{
if(!$info) $info = Context::getDBInfo(); if(!$info) $info = Context::getDBInfo();
if($info){ if($info)
if($target == 'object'){ {
if($target == 'object')
{
if($info->use_object_cache =='apc') $type = 'apc'; if($info->use_object_cache =='apc') $type = 'apc';
else if(substr($info->use_object_cache,0,8)=='memcache'){ else if(substr($info->use_object_cache,0,8)=='memcache')
{
$type = 'memcache'; $type = 'memcache';
$url = $info->use_object_cache; $url = $info->use_object_cache;
} else if($info->use_object_cache == 'wincache') $type = 'wincache'; }
else if($info->use_object_cache == 'wincache') $type = 'wincache';
else if($info->use_object_cache =='file') $type = 'file'; else if($info->use_object_cache =='file') $type = 'file';
else if($always_use_file) $type = 'file'; else if($always_use_file) $type = 'file';
}else if($target == 'template'){ }
else if($target == 'template')
{
if($info->use_template_cache =='apc') $type = 'apc'; if($info->use_template_cache =='apc') $type = 'apc';
else if(substr($info->use_template_cache,0,8)=='memcache'){ else if(substr($info->use_template_cache,0,8)=='memcache')
{
$type = 'memcache'; $type = 'memcache';
$url = $info->use_template_cache; $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); $class = 'Cache' . ucfirst($type);
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class); include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
$this->handler = call_user_func(array($class,'getInstance'), $url); $this->handler = call_user_func(array($class,'getInstance'), $url);
$this->keyGroupVersions = $this->handler->get('key_group_versions', 0); $this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
if(!$this->keyGroupVersions) { if(!$this->keyGroupVersions)
{
$this->keyGroupVersions = array(); $this->keyGroupVersions = array();
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0); $this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
} }
@ -81,7 +95,8 @@ class CacheHandler extends Handler {
* *
* @return boolean * @return boolean
*/ */
function isSupport(){ function isSupport()
{
if($this->handler && $this->handler->isSupport()) return true; if($this->handler && $this->handler->isSupport()) return true;
return false; return false;
} }
@ -94,7 +109,8 @@ class CacheHandler extends Handler {
* 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. * @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)
{
if(!$this->handler) return false; if(!$this->handler) return false;
return $this->handler->get($key, $modified_time); return $this->handler->get($key, $modified_time);
} }
@ -109,7 +125,8 @@ class CacheHandler extends Handler {
* If no ttl is supplied, use the default valid time. * 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. * @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)
{
if(!$this->handler) return false; if(!$this->handler) return false;
return $this->handler->put($key, $obj, $valid_time); return $this->handler->put($key, $obj, $valid_time);
} }
@ -120,7 +137,8 @@ class CacheHandler extends Handler {
* @param string $key Cache key * @param string $key Cache key
* @return void * @return void
*/ */
function delete($key){ function delete($key)
{
if(!$this->handler) return false; if(!$this->handler) return false;
return $this->handler->delete($key); return $this->handler->delete($key);
} }
@ -133,7 +151,8 @@ class CacheHandler extends Handler {
* 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. * @return bool Return true on valid or false on invalid.
*/ */
function isValid($key, $modified_time){ function isValid($key, $modified_time)
{
if(!$this->handler) return false; if(!$this->handler) return false;
return $this->handler->isValid($key, $modified_time); return $this->handler->isValid($key, $modified_time);
} }
@ -143,7 +162,8 @@ class CacheHandler extends Handler {
* *
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void. * @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
*/ */
function truncate(){ function truncate()
{
if(!$this->handler) return false; if(!$this->handler) return false;
return $this->handler->truncate(); return $this->handler->truncate();
} }
@ -164,8 +184,10 @@ class CacheHandler extends Handler {
* @param string $key Cache key * @param string $key Cache key
* @return string * @return string
*/ */
function getGroupKey($keyGroupName, $key){ function getGroupKey($keyGroupName, $key)
if(!$this->keyGroupVersions[$keyGroupName]){ {
if(!$this->keyGroupVersions[$keyGroupName])
{
$this->keyGroupVersions[$keyGroupName] = 1; $this->keyGroupVersions[$keyGroupName] = 1;
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0); $this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
} }
@ -179,7 +201,8 @@ class CacheHandler extends Handler {
* @param string $keyGroupName Group name * @param string $keyGroupName Group name
* @return void * @return void
*/ */
function invalidateGroupKey($keyGroupName){ function invalidateGroupKey($keyGroupName)
{
$this->keyGroupVersions[$keyGroupName]++; $this->keyGroupVersions[$keyGroupName]++;
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0); $this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
} }
@ -190,8 +213,8 @@ class CacheHandler extends Handler {
* *
* @author NHN (developer@xpressengine.com) * @author NHN (developer@xpressengine.com)
*/ */
class CacheBase{ class CacheBase
{
/** /**
* Get cached data * Get cached data
* *
@ -200,7 +223,8 @@ class CacheBase{
* 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. * @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; return false;
} }
@ -214,7 +238,8 @@ class CacheBase{
* If no ttl is supplied, use the default valid time. * 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. * @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; return false;
} }
@ -226,7 +251,8 @@ class CacheBase{
* 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. * @return bool Return true on valid or false on invalid.
*/ */
function isValid($key, $modified_time = 0){ function isValid($key, $modified_time = 0)
{
return false; return false;
} }
@ -235,7 +261,8 @@ class CacheBase{
* *
* @return boolean * @return boolean
*/ */
function isSupport(){ function isSupport()
{
return false; return false;
} }
@ -244,7 +271,8 @@ class CacheBase{
* *
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void. * @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
*/ */
function truncate(){ function truncate()
{
return false; return false;
} }
} }

View file

@ -3,8 +3,9 @@
* Cache class for memcache * Cache class for memcache
* *
* @author NHN (developer@xpressengine.com) * @author NHN (developer@xpressengine.com)
**/ */
class CacheMemcache extends CacheBase { class CacheMemcache extends CacheBase
{
/** /**
* Default valid time * Default valid time
* @var int * @var int
@ -23,7 +24,8 @@ class CacheMemcache extends CacheBase {
* @param string $url url of memcache * @param string $url url of memcache
* @return CacheMemcache instance of CacheMemcache * @return CacheMemcache instance of CacheMemcache
*/ */
function getInstance($url){ function getInstance($url)
{
if(!$GLOBALS['__CacheMemcache__']) { if(!$GLOBALS['__CacheMemcache__']) {
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url); $GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
} }
@ -37,12 +39,14 @@ class CacheMemcache extends CacheBase {
* @param string $url url of memcache * @param string $url url of memcache
* @return void * @return void
*/ */
function CacheMemcache($url){ function CacheMemcache($url)
{
//$config['url'] = array('memcache://localhost:11211'); //$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; $this->Memcache = new Memcache;
foreach($config['url'] as $url) { foreach($config['url'] as $url)
{
$info = parse_url($url); $info = parse_url($url);
$this->Memcache->addServer($info['host'], $info['port']); $this->Memcache->addServer($info['host'], $info['port']);
} }
@ -53,11 +57,15 @@ class CacheMemcache extends CacheBase {
* *
* @return bool Return true on support or false on not support * @return bool Return true on support or false on not support
*/ */
function isSupport(){ function isSupport()
{
if($GLOBALS['XE_MEMCACHE_SUPPORT']) return true; if($GLOBALS['XE_MEMCACHE_SUPPORT']) return true;
if($this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1)) { if($this->Memcache->set('xe', 'xe', MEMCACHE_COMPRESSED, 1))
{
$GLOBALS['XE_MEMCACHE_SUPPORT'] = true; $GLOBALS['XE_MEMCACHE_SUPPORT'] = true;
} else { }
else
{
$GLOBALS['XE_MEMCACHE_SUPPORT'] = false; $GLOBALS['XE_MEMCACHE_SUPPORT'] = false;
} }
return $GLOBALS['XE_MEMCACHE_SUPPORT']; return $GLOBALS['XE_MEMCACHE_SUPPORT'];
@ -69,7 +77,8 @@ class CacheMemcache extends CacheBase {
* @param string $key Cache key * @param string $key Cache key
* @return string Return unique key * @return string Return unique key
*/ */
function getKey($key){ function getKey($key)
{
return md5(_XE_PATH_.$key); return md5(_XE_PATH_.$key);
} }
@ -90,7 +99,8 @@ class CacheMemcache extends CacheBase {
* If it's equal to zero, use the default valid time CacheMemcache::valid_time. * If it's equal to zero, use the default valid time CacheMemcache::valid_time.
* @return bool Returns true on success or false on failure. * @return bool Returns true on success or false on failure.
*/ */
function put($key, $buff, $valid_time = 0){ function put($key, $buff, $valid_time = 0)
{
if($valid_time == 0) $valid_time = $this->valid_time; if($valid_time == 0) $valid_time = $this->valid_time;
return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time); return $this->Memcache->set($this->getKey($key), array(time(), $buff), MEMCACHE_COMPRESSED, $valid_time);
@ -104,14 +114,16 @@ class CacheMemcache extends CacheBase {
* 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. * @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); $_key = $this->getKey($key);
$obj = $this->Memcache->get($_key); $obj = $this->Memcache->get($_key);
if(!$obj || !is_array($obj)) return false; if(!$obj || !is_array($obj)) return false;
unset($obj[1]); unset($obj[1]);
if($modified_time > 0 && $modified_time > $obj[0]) { if($modified_time > 0 && $modified_time > $obj[0])
{
$this->_delete($_key); $this->_delete($_key);
return false; return false;
} }
@ -129,12 +141,14 @@ class CacheMemcache extends CacheBase {
* 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. * @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); $_key = $this->getKey($key);
$obj = $this->Memcache->get($_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); $this->_delete($_key);
return false; return false;
} }
@ -152,7 +166,8 @@ class CacheMemcache extends CacheBase {
* @param string $key The key associated with the item to delete. * @param string $key The key associated with the item to delete.
* @return void * @return void
*/ */
function delete($key) { function delete($key)
{
$_key = $this->getKey($key); $_key = $this->getKey($key);
$this->_delete($_key); $this->_delete($_key);
} }
@ -164,7 +179,8 @@ class CacheMemcache extends CacheBase {
* @param string $_key The key associated with the item to delete. * @param string $_key The key associated with the item to delete.
* @return void * @return void
*/ */
function _delete($_key) { function _delete($_key)
{
$this->Memcache->delete($_key); $this->Memcache->delete($_key);
} }
@ -177,7 +193,8 @@ class CacheMemcache extends CacheBase {
* *
* @return bool Returns true on success or false on failure. * @return bool Returns true on success or false on failure.
*/ */
function truncate() { function truncate()
{
return $this->Memcache->flush(); return $this->Memcache->flush();
} }
} }

View file

@ -1,11 +1,14 @@
<?php <?php
include '../handler/Handler.class.php';
include './CacheHandler.class.php';
/** /**
* Cache class for Wincache * Cache class for Wincache
* *
* Wincache Handler * Wincache Handler
* *
* @author Arnia (support@xpressengine.org) * @author Arnia (support@xpressengine.org)
**/ */
class CacheWincache extends CacheBase { class CacheWincache extends CacheBase {
/** /**
* Default valid time * Default valid time
@ -19,7 +22,8 @@ class CacheWincache extends CacheBase {
* @param void $opt Not used * @param void $opt Not used
* @return CacheWincache instance of CacheWincache * @return CacheWincache instance of CacheWincache
*/ */
function getInstance($opt=null){ function getInstance($opt=null)
{
if(!$GLOBALS['__CacheWincache__']) { if(!$GLOBALS['__CacheWincache__']) {
$GLOBALS['__CacheWincache__'] = new CacheWincache(); $GLOBALS['__CacheWincache__'] = new CacheWincache();
} }
@ -31,7 +35,8 @@ class CacheWincache extends CacheBase {
* *
* @return void * @return void
*/ */
function CacheWincache(){ function CacheWincache()
{
} }
/** /**
@ -39,7 +44,8 @@ class CacheWincache extends CacheBase {
* *
* @return bool Return true on support or false on not support * @return bool Return true on support or false on not support
*/ */
function isSupport(){ function isSupport()
{
return function_exists('wincache_ucache_set'); return function_exists('wincache_ucache_set');
} }
@ -54,7 +60,8 @@ class CacheWincache extends CacheBase {
* If no ttl is supplied, use the default valid time CacheWincache::valid_time. * If no ttl is supplied, use the default valid time CacheWincache::valid_time.
* @return bool Returns true on success or false on failure. * @return bool Returns true on success or false on failure.
*/ */
function put($key, $buff, $valid_time = 0){ function put($key, $buff, $valid_time = 0)
{
if($valid_time == 0) $valid_time = $this->valid_time; if($valid_time == 0) $valid_time = $this->valid_time;
return wincache_ucache_set(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time); return wincache_ucache_set(md5(_XE_PATH_.$key), array(time(), $buff), $valid_time);
} }
@ -67,13 +74,15 @@ class CacheWincache extends CacheBase {
* 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. * @return bool Return true on valid or false on invalid.
*/ */
function isValid($key, $modified_time = 0) { function isValid($key, $modified_time = 0)
{
$_key = md5(_XE_PATH_.$key); $_key = md5(_XE_PATH_.$key);
$obj = wincache_ucache_get($_key, $success); $obj = wincache_ucache_get($_key, $success);
if(!$success || !is_array($obj)) return false; if(!$success || !is_array($obj)) return false;
unset($obj[1]); unset($obj[1]);
if($modified_time > 0 && $modified_time > $obj[0]) { if($modified_time > 0 && $modified_time > $obj[0])
{
$this->_delete($_key); $this->_delete($_key);
return false; return false;
} }
@ -89,12 +98,14 @@ class CacheWincache extends CacheBase {
* 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. * @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 = md5(_XE_PATH_.$key); $_key = md5(_XE_PATH_.$key);
$obj = wincache_ucache_get($_key, $success); $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); $this->_delete($_key);
return false; return false;
} }
@ -108,7 +119,8 @@ class CacheWincache extends CacheBase {
* @param string $_key Used to store the value. * @param string $_key Used to store the value.
* @return void * @return void
*/ */
function _delete($_key) { function _delete($_key)
{
wincache_ucache_delete($_key); wincache_ucache_delete($_key);
} }
@ -118,7 +130,8 @@ class CacheWincache extends CacheBase {
* @param string $key Used to store the value. * @param string $key Used to store the value.
* @return void * @return void
*/ */
function delete($key) { function delete($key)
{
$_key = md5(_XE_PATH_.$key); $_key = md5(_XE_PATH_.$key);
$this->_delete($_key); $this->_delete($_key);
} }
@ -128,7 +141,8 @@ class CacheWincache extends CacheBase {
* *
* @return bool Returns true on success or false on failure. * @return bool Returns true on success or false on failure.
*/ */
function truncate() { function truncate()
{
return wincache_ucache_clear(); return wincache_ucache_clear();
} }
} }