mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +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.
|
||||
|
|
|
|||
|
|
@ -673,17 +673,21 @@ class adminAdminController extends admin
|
|||
{
|
||||
if ($vars->object_cache_type === 'memcached' || $vars->object_cache_type === 'redis')
|
||||
{
|
||||
$cache_config = $vars->object_cache_type . '://' . $vars->object_cache_host . ':' . intval($vars->object_cache_port);
|
||||
$cache_servers = array($vars->object_cache_type . '://' . $vars->object_cache_host . ':' . intval($vars->object_cache_port));
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache_config = $vars->object_cache_type;
|
||||
$cache_servers = array();
|
||||
}
|
||||
if (!Rhymix\Framework\Cache::getCacheDriver($vars->object_cache_type, array($cache_config)))
|
||||
if (!Rhymix\Framework\Cache::getCacheDriver($vars->object_cache_type, $cache_servers))
|
||||
{
|
||||
return new Object(-1, 'msg_cache_handler_not_supported');
|
||||
}
|
||||
Rhymix\Framework\Config::set('cache', array($cache_config));
|
||||
Rhymix\Framework\Config::set('cache', array(
|
||||
'type' => $vars->object_cache_type,
|
||||
'ttl' => intval($vars->cache_default_ttl ?: 86400),
|
||||
'servers' => $cache_servers,
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -451,23 +451,36 @@ class adminAdminView extends admin
|
|||
Context::set('https_port', Rhymix\Framework\Config::get('url.https_port'));
|
||||
|
||||
// Object cache
|
||||
$object_cache_config = Rhymix\Framework\Config::get('cache');
|
||||
if (is_array($object_cache_config))
|
||||
{
|
||||
$object_cache_config = array_first($object_cache_config);
|
||||
}
|
||||
$object_cache_types = Rhymix\Framework\Cache::getSupportedDrivers();
|
||||
$object_cache_type = preg_replace('/^memcache$/', 'memcached', preg_replace('/:.+$/', '', $object_cache_config));
|
||||
if (!$object_cache_type)
|
||||
{
|
||||
$object_cache_type = 'dummy';
|
||||
}
|
||||
Context::set('object_cache_types', $object_cache_types);
|
||||
Context::set('object_cache_type', $object_cache_type);
|
||||
$object_cache_type = Rhymix\Framework\Config::get('cache.type');
|
||||
if ($object_cache_type)
|
||||
{
|
||||
Context::set('object_cache_host', parse_url($object_cache_config, PHP_URL_HOST) ?: null);
|
||||
Context::set('object_cache_port', parse_url($object_cache_config, PHP_URL_PORT) ?: null);
|
||||
$cache_default_ttl = Rhymix\Framework\Config::get('cache.ttl');
|
||||
$cache_servers = Rhymix\Framework\Config::get('cache.servers');
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache_config = array_first(Rhymix\Framework\Config::get('cache'));
|
||||
if ($cache_config)
|
||||
{
|
||||
$object_cache_type = preg_replace('/^memcache$/', 'memcached', preg_replace('/:.+$/', '', $cache_config));
|
||||
}
|
||||
else
|
||||
{
|
||||
$object_cache_type = 'dummy';
|
||||
}
|
||||
$cache_default_ttl = 86400;
|
||||
$cache_servers = Rhymix\Framework\Config::get('cache');
|
||||
}
|
||||
|
||||
Context::set('object_cache_types', $object_cache_types);
|
||||
Context::set('object_cache_type', $object_cache_type);
|
||||
Context::set('cache_default_ttl', $cache_default_ttl);
|
||||
|
||||
if ($cache_servers)
|
||||
{
|
||||
Context::set('object_cache_host', parse_url(array_first($cache_servers), PHP_URL_HOST) ?: null);
|
||||
Context::set('object_cache_port', parse_url(array_first($cache_servers), PHP_URL_PORT) ?: null);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ $lang->about_minify_scripts = 'Automatically minify all CSS and JS scripts in th
|
|||
$lang->use_gzip = 'gzip Compression';
|
||||
$lang->delay_session = 'Delay session start';
|
||||
$lang->about_delay_session = 'To improve performance when using a caching proxy server such as Varnish, do not issue sessions to visitors until they log in.<br>Selecting this option may cause view counts and visitor counts to become inaccurate.';
|
||||
$lang->use_object_cache = 'Use Object Cache';
|
||||
$lang->use_object_cache_do_not_use = 'none';
|
||||
$lang->use_object_cache = 'Use Cache';
|
||||
$lang->cache_default_ttl = 'Cache default TTL';
|
||||
$lang->cache_host = 'Host';
|
||||
$lang->cache_port = 'Port';
|
||||
$lang->msg_cache_handler_not_supported = 'Your server does not support the selected cache method, or Rhymix is unable to use the cache with the given settings.';
|
||||
|
|
|
|||
|
|
@ -86,8 +86,7 @@ $lang->about_minify_scripts = 'コアとすべてのモジュールに含まれ
|
|||
$lang->use_gzip = 'gzip 圧縮';
|
||||
$lang->delay_session = 'セッションの開始を遅延';
|
||||
$lang->about_delay_session = 'Varnishなどのプロキシキャッシュサーバ使用時のパフォーマンスを向上させるために、ログインしていないユーザーには、認証セッションを付与しません。<br>このオプションを選択した場合、訪問者数とヒット集計が正確でない場合があります。';
|
||||
$lang->use_object_cache = 'オブジェクトキャッシュ';
|
||||
$lang->use_object_cache_do_not_use = '使用していない';
|
||||
$lang->use_object_cache = 'キャッシュ使用';
|
||||
$lang->cache_host = 'ホスト';
|
||||
$lang->cache_port = 'ポート';
|
||||
$lang->msg_cache_handler_not_supported = '選択したキャッシュ方式をサーバーでサポートされていないか、与えられた情報でキャッシュにアクセスすることができません。';
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ $lang->about_minify_scripts = '코어와 모든 모듈에 포함된 CSS, JS 파
|
|||
$lang->use_gzip = 'gzip 압축';
|
||||
$lang->delay_session = '세션 시작 지연';
|
||||
$lang->about_delay_session = 'Varnish 등의 프록시 캐싱 서버 사용시 성능 개선을 위해, 로그인하지 않은 사용자에게는 인증 세션을 부여하지 않습니다.<br>이 옵션을 선택할 경우 방문자 수 및 조회수 집계가 정확하게 이루어지지 않을 수 있습니다.';
|
||||
$lang->use_object_cache = '오브젝트 캐시 사용';
|
||||
$lang->use_object_cache_do_not_use = '사용하지 않음';
|
||||
$lang->use_object_cache = '캐시 사용';
|
||||
$lang->cache_default_ttl = '캐시 기본 TTL';
|
||||
$lang->cache_host = '호스트';
|
||||
$lang->cache_port = '포트';
|
||||
$lang->msg_cache_handler_not_supported = '선택하신 캐시 방식을 서버에서 지원하지 않거나, 주어진 정보로 캐시에 접속할 수 없습니다.';
|
||||
|
|
|
|||
|
|
@ -70,6 +70,12 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label" for="cache_default_ttl">{$lang->cache_default_ttl}</label>
|
||||
<div class="x_controls">
|
||||
<input type="text" name="cache_default_ttl" id="cache_default_ttl" value="{$cache_default_ttl}" /> {$lang->unit_sec}
|
||||
</div>
|
||||
</div>
|
||||
<div class="x_control-group">
|
||||
<label class="x_control-label">{$lang->minify_scripts}</label>
|
||||
<div class="x_controls">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue