Update admin module to use new Cache system

This commit is contained in:
Kijin Sung 2016-04-17 15:01:42 +09:00
parent 7d80bbe27d
commit 89ae581e55
11 changed files with 32 additions and 16 deletions

View file

@ -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;
}
}
}
/**

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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'))
{

View file

@ -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
{

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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.