Make object cache configurable via the admin UI

This commit is contained in:
Kijin Sung 2016-02-11 13:32:55 +09:00
parent 225f02cac2
commit f3d3122787
10 changed files with 113 additions and 6 deletions

View file

@ -103,9 +103,19 @@ class CacheHandler extends Handler
*
* @return boolean
*/
public function isSupport()
public function isSupport($type = null, $cache_config = null)
{
return ($this->handler && $this->handler->isSupport());
if ($type === null)
{
return ($this->handler && $this->handler->isSupport());
}
else
{
$class = 'Cache' . ucfirst(str_replace('memcached', 'memcache', $type));
include_once sprintf('%sclasses/cache/%s.class.php', _XE_PATH_, $class);
$handler = $class::getInstance($cache_config, true);
return $handler->isSupport();
}
}
/**
@ -129,6 +139,7 @@ class CacheHandler extends Handler
*/
public function get($key, $modified_time = 0)
{
if (!$key) return false;
return $this->handler ? $this->handler->get($this->getCacheKey($key), $modified_time) : false;
}
@ -144,6 +155,7 @@ class CacheHandler extends Handler
*/
public function put($key, $obj, $valid_time = 0)
{
if (!$key) return false;
return $this->handler ? $this->handler->put($this->getCacheKey($key), $obj, $valid_time) : false;
}
@ -155,6 +167,7 @@ class CacheHandler extends Handler
*/
public function delete($key)
{
if (!$key) return false;
return $this->handler ? $this->handler->delete($this->getCacheKey($key)) : false;
}
@ -168,6 +181,7 @@ class CacheHandler extends Handler
*/
public function isValid($key, $modified_time = 0)
{
if (!$key) return false;
return $this->handler ? $this->handler->isValid($this->getCacheKey($key), $modified_time) : false;
}

View file

@ -21,11 +21,12 @@ class CacheMemcache extends CacheBase
* @param string $url url of memcache
* @return CacheMemcache instance of CacheMemcache
*/
function getInstance($url)
function getInstance($url, $force_new_instance = false)
{
if(!$GLOBALS['__CacheMemcache__'])
if(!$GLOBALS['__CacheMemcache__'] || $force_new_instance)
{
$GLOBALS['__CacheMemcache__'] = new CacheMemcache($url);
unset($GLOBALS['XE_MEMCACHE_SUPPORT']);
}
return $GLOBALS['__CacheMemcache__'];
}

View file

@ -21,9 +21,9 @@ class CacheRedis extends CacheBase
* @param string $url url of Redis
* @return CacheRedis instance of CacheRedis
*/
function getInstance($url)
function getInstance($url, $force_new_instance = false)
{
if(!$GLOBALS['__CacheRedis__'])
if(!$GLOBALS['__CacheRedis__'] || $force_new_instance)
{
$GLOBALS['__CacheRedis__'] = new CacheRedis($url);
}