mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-27 06:13:32 +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
|
||||
|
|
|
|||
|
|
@ -137,7 +137,13 @@ class ConfigParser
|
|||
// Convert cache configuration.
|
||||
if (isset($db_info->use_object_cache))
|
||||
{
|
||||
$config['cache'][] = $db_info->use_object_cache;
|
||||
if (!is_array($db_info->use_object_cache))
|
||||
{
|
||||
$db_info->use_object_cache = array($db_info->use_object_cache);
|
||||
}
|
||||
$config['cache']['type'] = preg_replace('/^memcache$/', 'memcached', preg_replace('/:.+$/', '', array_first($db_info->use_object_cache)));
|
||||
$config['cache']['ttl'] = 86400;
|
||||
$config['cache']['servers'] = in_array($config['cache']['type'], array('memcached', 'redis')) ? $db_info->use_object_cache : array();
|
||||
}
|
||||
|
||||
// Convert FTP configuration.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue