mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-12 07:11:42 +09:00
Make all cache drivers singleton instances
This commit is contained in:
parent
9b71df6a01
commit
2227e0d278
10 changed files with 164 additions and 40 deletions
29
common/framework/drivers/cache/redis.php
vendored
29
common/framework/drivers/cache/redis.php
vendored
|
|
@ -12,18 +12,20 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface
|
|||
*/
|
||||
public $prefix = true;
|
||||
|
||||
/**
|
||||
* The singleton instance is stored here.
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* The Redis connection is stored here.
|
||||
*/
|
||||
protected $_conn = null;
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
* Direct invocation of the constructor is not permitted.
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
protected function __construct(array $config)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -53,6 +55,21 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance of the current cache driver, using the given settings.
|
||||
*
|
||||
* @param array $config
|
||||
* @return void
|
||||
*/
|
||||
public static function getInstance(array $config)
|
||||
{
|
||||
if (self::$_instance === null)
|
||||
{
|
||||
self::$_instance = new self($config);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current cache driver is supported on this server.
|
||||
*
|
||||
|
|
@ -60,7 +77,7 @@ class Redis implements \Rhymix\Framework\Drivers\CacheInterface
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupported()
|
||||
public static function isSupported()
|
||||
{
|
||||
return class_exists('\\Redis', false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue