mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-17 09:24:17 +09:00
Migrate cache configuration format, keeping backward compatibility
This commit is contained in:
parent
194cf3fa70
commit
050a507707
8 changed files with 70 additions and 28 deletions
|
|
@ -12,6 +12,11 @@ class Cache
|
|||
*/
|
||||
protected static $_driver = null;
|
||||
|
||||
/**
|
||||
* The default TTL.
|
||||
*/
|
||||
protected static $_ttl = 86400;
|
||||
|
||||
/**
|
||||
* The automatically generated cache prefix.
|
||||
*/
|
||||
|
|
@ -30,9 +35,14 @@ class Cache
|
|||
$config = array($config);
|
||||
}
|
||||
|
||||
if (isset($config['driver']))
|
||||
if (isset($config['type']))
|
||||
{
|
||||
$class_name = '\\Rhymix\\Framework\\Drivers\\Cache\\' . $config['driver'];
|
||||
$class_name = '\\Rhymix\\Framework\\Drivers\\Cache\\' . $config['type'];
|
||||
if (isset($config['ttl']))
|
||||
{
|
||||
self::$_ttl = intval($config['ttl']);
|
||||
}
|
||||
$config = isset($config['servers']) ? $config['servers'] : array();
|
||||
}
|
||||
elseif (preg_match('/^(apc|dummy|file|memcache|redis|sqlite|wincache|xcache)/', strval(array_first($config)), $matches))
|
||||
{
|
||||
|
|
@ -148,7 +158,7 @@ class Cache
|
|||
* @param string $group_name (optional)
|
||||
* @return bool
|
||||
*/
|
||||
public static function set($key, $value, $ttl = 0, $group_name = null)
|
||||
public static function set($key, $value, $ttl = null, $group_name = null)
|
||||
{
|
||||
if (self::$_driver !== null)
|
||||
{
|
||||
|
|
@ -156,6 +166,10 @@ class Cache
|
|||
{
|
||||
$ttl = min(3600 * 24 * 30, max(0, $ttl - time()));
|
||||
}
|
||||
if ($ttl === null)
|
||||
{
|
||||
$ttl = self::$_ttl;
|
||||
}
|
||||
return self::$_driver->set(self::getRealKey($key, $group_name), $value, intval($ttl)) ? true : false;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue