mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
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:
parent
f9fbd4a307
commit
cc1d9775ef
7 changed files with 186 additions and 94 deletions
44
classes/cache/CacheApc.class.php
vendored
44
classes/cache/CacheApc.class.php
vendored
|
|
@ -1,10 +1,14 @@
|
|||
<?php
|
||||
include '../handler/Handler.class.php';
|
||||
include './CacheHandler.class.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 +21,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 +35,8 @@ 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');
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +59,8 @@ class CacheApc extends CacheBase {
|
|||
* 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){
|
||||
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);
|
||||
}
|
||||
|
|
@ -64,17 +73,19 @@ class CacheApc extends CacheBase {
|
|||
* 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 = 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]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -86,12 +97,14 @@ class CacheApc extends CacheBase {
|
|||
* 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 = md5(_XE_PATH_.$key);
|
||||
$obj = apc_fetch($_key, $success);
|
||||
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,7 +118,8 @@ class CacheApc extends CacheBase {
|
|||
* @param string $_key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function _delete($_key) {
|
||||
function _delete($_key)
|
||||
{
|
||||
$this->put($_key,null,1);
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +129,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,7 +139,8 @@ class CacheApc extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
return apc_clear_cache('user');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
46
classes/cache/CacheFile.class.php
vendored
46
classes/cache/CacheFile.class.php
vendored
|
|
@ -1,12 +1,16 @@
|
|||
<?php
|
||||
include '../handler/Handler.class.php';
|
||||
include './CacheHandler.class.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,13 +22,14 @@ class CacheFile extends CacheBase {
|
|||
* @var string
|
||||
*/
|
||||
var $cache_dir = 'files/cache/store/';
|
||||
|
||||
|
||||
/**
|
||||
* Get instance of CacheFile
|
||||
*
|
||||
* @return CacheFile instance of CacheFile
|
||||
*/
|
||||
function getInstance(){
|
||||
function getInstance()
|
||||
{
|
||||
if(!$GLOBALS['__CacheFile__']) {
|
||||
$GLOBALS['__CacheFile__'] = new CacheFile();
|
||||
}
|
||||
|
|
@ -36,7 +41,8 @@ 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);
|
||||
}
|
||||
|
|
@ -47,16 +53,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,7 +76,8 @@ class CacheFile extends CacheBase {
|
|||
* @param int $valid_time Not used
|
||||
* @return void
|
||||
*/
|
||||
function put($key, $obj, $valid_time = 0){
|
||||
function put($key, $obj, $valid_time = 0)
|
||||
{
|
||||
$cache_file = $this->getCacheFileName($key);
|
||||
$text = serialize($obj);
|
||||
FileHandler::writeFile($cache_file, $text);
|
||||
|
|
@ -81,10 +90,11 @@ 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;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -95,11 +105,12 @@ 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;
|
||||
|
||||
|
||||
return unserialize($content);
|
||||
}
|
||||
|
||||
|
|
@ -109,7 +120,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 +132,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,7 +142,8 @@ class CacheFile extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
FileHandler::removeFilesInDir($this->cache_dir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
96
classes/cache/CacheHandler.class.php
vendored
96
classes/cache/CacheHandler.class.php
vendored
|
|
@ -3,8 +3,9 @@
|
|||
* CacheHandler
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
**/
|
||||
class CacheHandler extends Handler {
|
||||
*/
|
||||
class CacheHandler extends Handler
|
||||
{
|
||||
/**
|
||||
* instance of cache handler
|
||||
* @var CacheBase
|
||||
|
|
@ -25,9 +26,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 +47,45 @@ 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) {
|
||||
function CacheHandler($target, $info = null, $always_use_file = false)
|
||||
{
|
||||
if(!$info) $info = Context::getDBInfo();
|
||||
if($info){
|
||||
if($target == 'object'){
|
||||
if($info)
|
||||
{
|
||||
if($target == 'object')
|
||||
{
|
||||
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';
|
||||
$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($always_use_file) $type = 'file';
|
||||
}else if($target == 'template'){
|
||||
}
|
||||
else if($target == 'template')
|
||||
{
|
||||
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';
|
||||
$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->keyGroupVersions = $this->handler->get('key_group_versions', 0);
|
||||
if(!$this->keyGroupVersions)
|
||||
{
|
||||
$this->keyGroupVersions = array();
|
||||
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,7 +95,8 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
if($this->handler && $this->handler->isSupport()) return true;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -94,7 +109,8 @@ class CacheHandler extends Handler {
|
|||
* 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)
|
||||
{
|
||||
if(!$this->handler) return false;
|
||||
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.
|
||||
* @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;
|
||||
return $this->handler->put($key, $obj, $valid_time);
|
||||
}
|
||||
|
|
@ -120,7 +137,8 @@ class CacheHandler extends Handler {
|
|||
* @param string $key Cache key
|
||||
* @return void
|
||||
*/
|
||||
function delete($key){
|
||||
function delete($key)
|
||||
{
|
||||
if(!$this->handler) return false;
|
||||
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.
|
||||
* @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;
|
||||
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.
|
||||
*/
|
||||
function truncate(){
|
||||
function truncate()
|
||||
{
|
||||
if(!$this->handler) return false;
|
||||
return $this->handler->truncate();
|
||||
}
|
||||
|
|
@ -164,8 +184,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,7 +201,8 @@ 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,8 +213,8 @@ class CacheHandler extends Handler {
|
|||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
*/
|
||||
class CacheBase{
|
||||
|
||||
class CacheBase
|
||||
{
|
||||
/**
|
||||
* Get cached data
|
||||
*
|
||||
|
|
@ -200,7 +223,8 @@ class CacheBase{
|
|||
* 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;
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +238,8 @@ class CacheBase{
|
|||
* 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;
|
||||
}
|
||||
|
||||
|
|
@ -226,7 +251,8 @@ class CacheBase{
|
|||
* 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 +261,8 @@ class CacheBase{
|
|||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +271,8 @@ class CacheBase{
|
|||
*
|
||||
* @return bool|void Returns true on success or false on failure. If use CacheFile, returns void.
|
||||
*/
|
||||
function truncate(){
|
||||
function truncate()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
51
classes/cache/CacheMemcache.class.php
vendored
51
classes/cache/CacheMemcache.class.php
vendored
|
|
@ -3,8 +3,9 @@
|
|||
* Cache class for memcache
|
||||
*
|
||||
* @author NHN (developer@xpressengine.com)
|
||||
**/
|
||||
class CacheMemcache extends CacheBase {
|
||||
*/
|
||||
class CacheMemcache extends CacheBase
|
||||
{
|
||||
/**
|
||||
* Default valid time
|
||||
* @var int
|
||||
|
|
@ -23,7 +24,8 @@ class CacheMemcache extends CacheBase {
|
|||
* @param string $url url of memcache
|
||||
* @return CacheMemcache instance of CacheMemcache
|
||||
*/
|
||||
function getInstance($url){
|
||||
function getInstance($url)
|
||||
{
|
||||
if(!$GLOBALS['__CacheMemcache__']) {
|
||||
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
|
||||
}
|
||||
|
|
@ -37,12 +39,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);
|
||||
$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 +57,15 @@ class CacheMemcache extends CacheBase {
|
|||
*
|
||||
* @return bool Return true on support or false on not support
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
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;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$GLOBALS['XE_MEMCACHE_SUPPORT'] = false;
|
||||
}
|
||||
return $GLOBALS['XE_MEMCACHE_SUPPORT'];
|
||||
|
|
@ -69,7 +77,8 @@ class CacheMemcache extends CacheBase {
|
|||
* @param string $key Cache key
|
||||
* @return string Return unique key
|
||||
*/
|
||||
function getKey($key){
|
||||
function getKey($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.
|
||||
* @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;
|
||||
|
||||
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.
|
||||
* @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;
|
||||
unset($obj[1]);
|
||||
|
||||
if($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -129,12 +141,14 @@ class CacheMemcache extends CacheBase {
|
|||
* 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($modified_time > 0 && $modified_time > $obj[0]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -152,7 +166,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 +179,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,7 +193,8 @@ class CacheMemcache extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
return $this->Memcache->flush();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
38
classes/cache/CacheWincache.class.php
vendored
38
classes/cache/CacheWincache.class.php
vendored
|
|
@ -1,11 +1,14 @@
|
|||
<?php
|
||||
include '../handler/Handler.class.php';
|
||||
include './CacheHandler.class.php';
|
||||
|
||||
/**
|
||||
* Cache class for Wincache
|
||||
*
|
||||
* Wincache Handler
|
||||
*
|
||||
* @author Arnia (support@xpressengine.org)
|
||||
**/
|
||||
*/
|
||||
class CacheWincache extends CacheBase {
|
||||
/**
|
||||
* Default valid time
|
||||
|
|
@ -19,7 +22,8 @@ class CacheWincache extends CacheBase {
|
|||
* @param void $opt Not used
|
||||
* @return CacheWincache instance of CacheWincache
|
||||
*/
|
||||
function getInstance($opt=null){
|
||||
function getInstance($opt=null)
|
||||
{
|
||||
if(!$GLOBALS['__CacheWincache__']) {
|
||||
$GLOBALS['__CacheWincache__'] = new CacheWincache();
|
||||
}
|
||||
|
|
@ -31,7 +35,8 @@ class CacheWincache extends CacheBase {
|
|||
*
|
||||
* @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
|
||||
*/
|
||||
function isSupport(){
|
||||
function isSupport()
|
||||
{
|
||||
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.
|
||||
* @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;
|
||||
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.
|
||||
* @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);
|
||||
$obj = wincache_ucache_get($_key, $success);
|
||||
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;
|
||||
}
|
||||
|
|
@ -89,12 +98,14 @@ class CacheWincache extends CacheBase {
|
|||
* 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 = 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]) {
|
||||
if($modified_time > 0 && $modified_time > $obj[0])
|
||||
{
|
||||
$this->_delete($_key);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -108,7 +119,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,7 +130,8 @@ class CacheWincache extends CacheBase {
|
|||
* @param string $key Used to store the value.
|
||||
* @return void
|
||||
*/
|
||||
function delete($key) {
|
||||
function delete($key)
|
||||
{
|
||||
$_key = md5(_XE_PATH_.$key);
|
||||
$this->_delete($_key);
|
||||
}
|
||||
|
|
@ -128,7 +141,8 @@ class CacheWincache extends CacheBase {
|
|||
*
|
||||
* @return bool Returns true on success or false on failure.
|
||||
*/
|
||||
function truncate() {
|
||||
function truncate()
|
||||
{
|
||||
return wincache_ucache_clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue