issue 2119. supporting php 5.4.

git-svn-id: http://xe-core.googlecode.com/svn/branches/maserati@12684 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2013-02-04 08:37:09 +00:00
parent 854e45afaa
commit bd1fa3651d
5 changed files with 173 additions and 75 deletions

View file

@ -1,11 +1,13 @@
<?php
/**
* Cache class for APC
*
* @author NHN (developer@xpressengine.com)
**/
* */
class CacheApc extends CacheBase
{
/**
* Default valid time
* @var int
@ -18,7 +20,7 @@ class CacheApc extends CacheBase
* @param void $opt Not used
* @return CacheApc instance of CacheApc
*/
function getInstance($opt=null)
function getInstance($opt = null)
{
if(!$GLOBALS['__CacheApc__'])
{
@ -34,6 +36,7 @@ class CacheApc extends CacheBase
*/
function CacheApc()
{
}
/**
@ -58,8 +61,12 @@ class CacheApc extends CacheBase
*/
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);
if($valid_time == 0)
{
$valid_time = $this->valid_time;
}
return apc_store(md5(_XE_PATH_ . $key), array(time(), $buff), $valid_time);
}
/**
@ -72,9 +79,12 @@ class CacheApc extends CacheBase
*/
function isValid($key, $modified_time = 0)
{
$_key = md5(_XE_PATH_.$key);
$_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])
@ -96,9 +106,12 @@ class CacheApc extends CacheBase
*/
function get($key, $modified_time = 0)
{
$_key = md5(_XE_PATH_.$key);
$_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])
{
@ -117,7 +130,7 @@ class CacheApc extends CacheBase
*/
function _delete($_key)
{
$this->put($_key,null,1);
$this->put($_key, null, 1);
}
/**
@ -140,7 +153,7 @@ class CacheApc extends CacheBase
{
return apc_clear_cache('user');
}
}
}
/* End of file CacheApc.class.php */
/* Location: ./classes/cache/CacheApc.class.php */

View file

@ -1,4 +1,5 @@
<?php
/**
* Cache class for file
*
@ -8,6 +9,7 @@
*/
class CacheFile extends CacheBase
{
/**
* Default valid time
* @var int
@ -27,7 +29,8 @@ class CacheFile extends CacheBase
*/
function getInstance()
{
if(!$GLOBALS['__CacheFile__']) {
if(!$GLOBALS['__CacheFile__'])
{
$GLOBALS['__CacheFile__'] = new CacheFile();
}
return $GLOBALS['__CacheFile__'];
@ -41,7 +44,10 @@ class CacheFile extends CacheBase
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);
}
}
/**
@ -90,7 +96,10 @@ class CacheFile extends CacheBase
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;
}
@ -106,7 +115,10 @@ class CacheFile extends CacheBase
{
$cache_file = $this->getCacheFileName($key);
$content = FileHandler::readFile($cache_file);
if(!$content) return false;
if(!$content)
{
return false;
}
return unserialize($content);
}
@ -143,7 +155,7 @@ class CacheFile extends CacheBase
{
FileHandler::removeFilesInDir($this->cache_dir);
}
}
}
/* End of file CacheFile.class.php */
/* Location: ./classes/cache/CacheFile.class.php */

View file

@ -1,4 +1,5 @@
<?php
/**
* CacheHandler
*
@ -6,6 +7,7 @@
*/
class CacheHandler extends Handler
{
/**
* instance of cache handler
* @var CacheBase
@ -49,37 +51,59 @@ class CacheHandler extends Handler
*/
function CacheHandler($target, $info = null, $always_use_file = false)
{
if(!$info) $info = Context::getDBInfo();
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')
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($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')
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)
{
$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->handler = call_user_func(array($class, 'getInstance'), $url);
$this->keyGroupVersions = $this->handler->get('key_group_versions', 0);
if(!$this->keyGroupVersions)
{
@ -97,7 +121,10 @@ class CacheHandler extends Handler
*/
function isSupport()
{
if($this->handler && $this->handler->isSupport()) return true;
if($this->handler && $this->handler->isSupport())
{
return true;
}
return false;
}
@ -111,7 +138,10 @@ class CacheHandler extends Handler
*/
function get($key, $modified_time = 0)
{
if(!$this->handler) return false;
if(!$this->handler)
{
return false;
}
return $this->handler->get($key, $modified_time);
}
@ -127,7 +157,10 @@ class CacheHandler extends Handler
*/
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);
}
@ -139,7 +172,10 @@ class CacheHandler extends Handler
*/
function delete($key)
{
if(!$this->handler) return false;
if(!$this->handler)
{
return false;
}
return $this->handler->delete($key);
}
@ -153,7 +189,10 @@ class CacheHandler extends Handler
*/
function isValid($key, $modified_time)
{
if(!$this->handler) return false;
if(!$this->handler)
{
return false;
}
return $this->handler->isValid($key, $modified_time);
}
@ -164,7 +203,10 @@ class CacheHandler extends Handler
*/
function truncate()
{
if(!$this->handler) return false;
if(!$this->handler)
{
return false;
}
return $this->handler->truncate();
}
@ -206,6 +248,7 @@ class CacheHandler extends Handler
$this->keyGroupVersions[$keyGroupName]++;
$this->handler->put('key_group_versions', $this->keyGroupVersions, 0);
}
}
/**
@ -215,6 +258,7 @@ class CacheHandler extends Handler
*/
class CacheBase
{
/**
* Get cached data
*
@ -275,7 +319,7 @@ class CacheBase
{
return false;
}
}
}
/* End of file CacheHandler.class.php */
/* Location: ./classes/cache/CacheHandler.class.php */

View file

@ -1,4 +1,5 @@
<?php
/**
* Cache class for memcache
*
@ -6,6 +7,7 @@
*/
class CacheMemcache extends CacheBase
{
/**
* Default valid time
* @var int
@ -26,7 +28,8 @@ class CacheMemcache extends CacheBase
*/
function getInstance($url)
{
if(!$GLOBALS['__CacheMemcache__']) {
if(!$GLOBALS['__CacheMemcache__'])
{
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
}
return $GLOBALS['__CacheMemcache__'];
@ -42,7 +45,7 @@ class CacheMemcache extends CacheBase
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)
@ -59,7 +62,10 @@ class CacheMemcache extends CacheBase
*/
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))
{
$GLOBALS['XE_MEMCACHE_SUPPORT'] = true;
@ -79,7 +85,7 @@ class CacheMemcache extends CacheBase
*/
function getKey($key)
{
return md5(_XE_PATH_.$key);
return md5(_XE_PATH_ . $key);
}
/**
@ -101,7 +107,10 @@ class CacheMemcache extends CacheBase
*/
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);
}
@ -119,7 +128,10 @@ class CacheMemcache extends CacheBase
$_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])
@ -145,7 +157,10 @@ class CacheMemcache extends CacheBase
{
$_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])
{
@ -197,7 +212,7 @@ class CacheMemcache extends CacheBase
{
return $this->Memcache->flush();
}
}
}
/* End of file CacheMemcache.class.php */
/* Location: ./classes/cache/CacheMemcache.class.php */

View file

@ -1,4 +1,5 @@
<?php
/**
* Cache class for Wincache
*
@ -6,7 +7,9 @@
*
* @author Arnia (support@xpressengine.org)
*/
class CacheWincache extends CacheBase {
class CacheWincache extends CacheBase
{
/**
* Default valid time
* @var int
@ -19,9 +22,10 @@ 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__'])
{
if(!$GLOBALS['__CacheWincache__']) {
$GLOBALS['__CacheWincache__'] = new CacheWincache();
}
return $GLOBALS['__CacheWincache__'];
@ -34,6 +38,7 @@ class CacheWincache extends CacheBase {
*/
function CacheWincache()
{
}
/**
@ -59,8 +64,11 @@ class CacheWincache extends CacheBase {
*/
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);
if($valid_time == 0)
{
$valid_time = $this->valid_time;
}
return wincache_ucache_set(md5(_XE_PATH_ . $key), array(time(), $buff), $valid_time);
}
/**
@ -73,9 +81,12 @@ class CacheWincache extends CacheBase {
*/
function isValid($key, $modified_time = 0)
{
$_key = md5(_XE_PATH_.$key);
$_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])
@ -97,9 +108,12 @@ class CacheWincache extends CacheBase {
*/
function get($key, $modified_time = 0)
{
$_key = md5(_XE_PATH_.$key);
$_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])
{
@ -129,7 +143,7 @@ class CacheWincache extends CacheBase {
*/
function delete($key)
{
$_key = md5(_XE_PATH_.$key);
$_key = md5(_XE_PATH_ . $key);
$this->_delete($_key);
}
@ -142,7 +156,7 @@ class CacheWincache extends CacheBase {
{
return wincache_ucache_clear();
}
}
}
/* End of file CacheWincache.class.php */
/* Location: ./classes/cache/CacheWincache.class.php */