From 89ae581e554ba8fd5c13718c9de5dfea9ca0ba16 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 17 Apr 2016 15:01:42 +0900 Subject: [PATCH] Update admin module to use new Cache system --- common/autoload.php | 1 - common/framework/cache.php | 27 ++++++++++++++++---- common/framework/drivers/cache/apc.php | 2 +- common/framework/drivers/cache/file.php | 2 +- common/framework/drivers/cache/memcached.php | 2 +- common/framework/drivers/cache/redis.php | 2 +- common/framework/drivers/cache/wincache.php | 2 +- common/framework/drivers/cache/xcache.php | 2 +- common/framework/drivers/cacheinterface.php | 2 +- modules/admin/admin.admin.controller.php | 2 +- modules/admin/admin.admin.view.php | 4 +-- 11 files changed, 32 insertions(+), 16 deletions(-) diff --git a/common/autoload.php b/common/autoload.php index d1720fc07..89bd85c4b 100644 --- a/common/autoload.php +++ b/common/autoload.php @@ -46,7 +46,6 @@ if(file_exists(RX_BASEDIR . 'config/config.user.inc.php')) * Define the list of legacy class names for the autoloader. */ $GLOBALS['RX_AUTOLOAD_FILE_MAP'] = array_change_key_case(array( - 'CacheBase' => 'classes/cache/CacheHandler.class.php', 'CacheHandler' => 'classes/cache/CacheHandler.class.php', 'Context' => 'classes/context/Context.class.php', 'DB' => 'classes/db/DB.class.php', diff --git a/common/framework/cache.php b/common/framework/cache.php index e8718ef24..805f1a1ac 100644 --- a/common/framework/cache.php +++ b/common/framework/cache.php @@ -64,7 +64,7 @@ class Cache foreach (Storage::readDirectory(__DIR__ . '/drivers/cache', false) as $filename) { $driver_name = substr($filename, 0, -4); - $class_name = '\Rhymix\Framework\Drivers\Cache\'' . $driver_name; + $class_name = '\Rhymix\Framework\Drivers\Cache\\' . $driver_name; if ($class_name::isSupported()) { $result[] = $driver_name; @@ -74,13 +74,30 @@ class Cache } /** - * Get the currently enabled cache driver. + * Get the currently enabled cache driver, or a named driver with the given settings. * - * return object|null + * @param string $name (optional) + * @param array $config (optional) + * @return object|null */ - public static function getCacheDriver() + public static function getCacheDriver($name = null, array $config = []) { - return self::$_driver; + if ($name === null) + { + return self::$_driver; + } + else + { + $class_name = '\\Rhymix\\Framework\\Drivers\\Cache\\' . $name; + if (class_exists($class_name) && $class_name::isSupported() && $class_name::validateSettings($config)) + { + return new $class_name($config); + } + else + { + return null; + } + } } /** diff --git a/common/framework/drivers/cache/apc.php b/common/framework/drivers/cache/apc.php index 8b23b45e9..5b0a7456d 100644 --- a/common/framework/drivers/cache/apc.php +++ b/common/framework/drivers/cache/apc.php @@ -38,7 +38,7 @@ class APC implements \Rhymix\Framework\Drivers\CacheInterface * @param mixed $config * @return bool */ - public function validateSettings($config) + public static function validateSettings($config) { return true; } diff --git a/common/framework/drivers/cache/file.php b/common/framework/drivers/cache/file.php index 8d3ce0cdd..a6a7fd2f3 100644 --- a/common/framework/drivers/cache/file.php +++ b/common/framework/drivers/cache/file.php @@ -49,7 +49,7 @@ class File implements \Rhymix\Framework\Drivers\CacheInterface * @param mixed $config * @return bool */ - public function validateSettings($config) + public static function validateSettings($config) { return true; } diff --git a/common/framework/drivers/cache/memcached.php b/common/framework/drivers/cache/memcached.php index 08eb54760..497b1d8cf 100644 --- a/common/framework/drivers/cache/memcached.php +++ b/common/framework/drivers/cache/memcached.php @@ -66,7 +66,7 @@ class Memcached implements \Rhymix\Framework\Drivers\CacheInterface * @param mixed $config * @return bool */ - public function validateSettings($config) + public static function validateSettings($config) { if (class_exists('\\Memcached')) { diff --git a/common/framework/drivers/cache/redis.php b/common/framework/drivers/cache/redis.php index de304c853..c6c59f814 100644 --- a/common/framework/drivers/cache/redis.php +++ b/common/framework/drivers/cache/redis.php @@ -68,7 +68,7 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface * @param mixed $config * @return bool */ - public function validateSettings($config) + public static function validateSettings($config) { try { diff --git a/common/framework/drivers/cache/wincache.php b/common/framework/drivers/cache/wincache.php index 769343298..d2cf2d730 100644 --- a/common/framework/drivers/cache/wincache.php +++ b/common/framework/drivers/cache/wincache.php @@ -38,7 +38,7 @@ class WinCache implements \Rhymix\Framework\Drivers\CacheInterface * @param mixed $config * @return bool */ - public function validateSettings($config) + public static function validateSettings($config) { return true; } diff --git a/common/framework/drivers/cache/xcache.php b/common/framework/drivers/cache/xcache.php index 9f9cd850a..8e0a6a61c 100644 --- a/common/framework/drivers/cache/xcache.php +++ b/common/framework/drivers/cache/xcache.php @@ -38,7 +38,7 @@ class XCache implements \Rhymix\Framework\Drivers\CacheInterface * @param mixed $config * @return bool */ - public function validateSettings($config) + public static function validateSettings($config) { return true; } diff --git a/common/framework/drivers/cacheinterface.php b/common/framework/drivers/cacheinterface.php index 117e67d45..1b7a8a646 100644 --- a/common/framework/drivers/cacheinterface.php +++ b/common/framework/drivers/cacheinterface.php @@ -32,7 +32,7 @@ interface CacheInterface * @param mixed $config * @return bool */ - public function validateSettings($config); + public static function validateSettings($config); /** * Get the value of a key. diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index 95f0813ee..86ef949fb 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -673,7 +673,7 @@ class adminAdminController extends admin { $cache_config = $vars->object_cache_type; } - if (!CacheHandler::isSupport($vars->object_cache_type, $cache_config)) + if (!Rhymix\Framework\Cache::getCacheDriver($vars->object_cache_type, array($cache_config))) { return new Object(-1, 'msg_cache_handler_not_supported'); } diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index d77f7e0e3..d030b7993 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -456,8 +456,8 @@ class adminAdminView extends admin { $object_cache_config = array_first($object_cache_config); } - $object_cache_types = array('apc', 'file', 'memcached', 'redis', 'wincache'); - $object_cache_type = preg_match('/^(' . implode('|', $object_cache_types) . ')/', $object_cache_config, $matches) ? $matches[1] : ''; + $object_cache_types = Rhymix\Framework\Cache::getSupportedDrivers(); + $object_cache_type = preg_replace('/^memcache$/', 'memcached', preg_replace('/:.+$/', '', $object_cache_config)); Context::set('object_cache_types', $object_cache_types); Context::set('object_cache_type', $object_cache_type); if ($object_cache_type)