From 050a507707cfc73ebffdd7309a4bdcb68f50a654 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 17 Apr 2016 19:52:31 +0900 Subject: [PATCH] Migrate cache configuration format, keeping backward compatibility --- common/framework/cache.php | 20 +++++++++-- common/framework/parsers/configparser.php | 8 ++++- modules/admin/admin.admin.controller.php | 12 ++++--- modules/admin/admin.admin.view.php | 41 +++++++++++++++-------- modules/admin/lang/en.php | 4 +-- modules/admin/lang/ja.php | 3 +- modules/admin/lang/ko.php | 4 +-- modules/admin/tpl/config_advanced.html | 6 ++++ 8 files changed, 70 insertions(+), 28 deletions(-) diff --git a/common/framework/cache.php b/common/framework/cache.php index e9cf22489..223e4f93e 100644 --- a/common/framework/cache.php +++ b/common/framework/cache.php @@ -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 diff --git a/common/framework/parsers/configparser.php b/common/framework/parsers/configparser.php index 51cf3a250..c8bff4e49 100644 --- a/common/framework/parsers/configparser.php +++ b/common/framework/parsers/configparser.php @@ -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. diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index 1d95874e8..010292d69 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -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 { diff --git a/modules/admin/admin.admin.view.php b/modules/admin/admin.admin.view.php index 52758776a..62f71b09e 100644 --- a/modules/admin/admin.admin.view.php +++ b/modules/admin/admin.admin.view.php @@ -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 { diff --git a/modules/admin/lang/en.php b/modules/admin/lang/en.php index fdb64d690..3e0edabf8 100644 --- a/modules/admin/lang/en.php +++ b/modules/admin/lang/en.php @@ -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.
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.'; diff --git a/modules/admin/lang/ja.php b/modules/admin/lang/ja.php index 9717c89fd..caa9b2df6 100644 --- a/modules/admin/lang/ja.php +++ b/modules/admin/lang/ja.php @@ -86,8 +86,7 @@ $lang->about_minify_scripts = 'コアとすべてのモジュールに含まれ $lang->use_gzip = 'gzip 圧縮'; $lang->delay_session = 'セッションの開始を遅延'; $lang->about_delay_session = 'Varnishなどのプロキシキャッシュサーバ使用時のパフォーマンスを向上させるために、ログインしていないユーザーには、認証セッションを付与しません。
このオプションを選択した場合、訪問者数とヒット集計が正確でない場合があります。'; -$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 = '選択したキャッシュ方式をサーバーでサポートされていないか、与えられた情報でキャッシュにアクセスすることができません。'; diff --git a/modules/admin/lang/ko.php b/modules/admin/lang/ko.php index de312abec..b115f00e9 100644 --- a/modules/admin/lang/ko.php +++ b/modules/admin/lang/ko.php @@ -89,8 +89,8 @@ $lang->about_minify_scripts = '코어와 모든 모듈에 포함된 CSS, JS 파 $lang->use_gzip = 'gzip 압축'; $lang->delay_session = '세션 시작 지연'; $lang->about_delay_session = 'Varnish 등의 프록시 캐싱 서버 사용시 성능 개선을 위해, 로그인하지 않은 사용자에게는 인증 세션을 부여하지 않습니다.
이 옵션을 선택할 경우 방문자 수 및 조회수 집계가 정확하게 이루어지지 않을 수 있습니다.'; -$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 = '선택하신 캐시 방식을 서버에서 지원하지 않거나, 주어진 정보로 캐시에 접속할 수 없습니다.'; diff --git a/modules/admin/tpl/config_advanced.html b/modules/admin/tpl/config_advanced.html index 8733cb0ff..2bc11806e 100644 --- a/modules/admin/tpl/config_advanced.html +++ b/modules/admin/tpl/config_advanced.html @@ -70,6 +70,12 @@ +
+ +
+ {$lang->unit_sec} +
+