Commit 88ba1a59 by Scott

Add option to choose caching driver

parent 1152e3f6
...@@ -39,7 +39,20 @@ class Q2A_Storage_CacheFactory ...@@ -39,7 +39,20 @@ class Q2A_Storage_CacheFactory
'dir' => defined('QA_CACHE_DIRECTORY') ? QA_CACHE_DIRECTORY : null, 'dir' => defined('QA_CACHE_DIRECTORY') ? QA_CACHE_DIRECTORY : null,
); );
self::$cacheDriver = new Q2A_Storage_FileCacheDriver($config); $driver = qa_opt('caching_driver');
switch($driver)
{
case 'memcached':
self::$cacheDriver = new Q2A_Storage_MemcachedDriver($config);
break;
case 'filesystem':
default:
self::$cacheDriver = new Q2A_Storage_FileCacheDriver($config);
break;
}
} }
return self::$cacheDriver; return self::$cacheDriver;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Question2Answer by Gideon Greenspan and contributors Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/ http://www.question2answer.org/
File: qa-include/Q2A/Storage/FileCache.php File: qa-include/Q2A/Storage/FileCacheDriver.php
Description: File-based driver for caching system. Description: File-based driver for caching system.
......
...@@ -176,11 +176,16 @@ class Q2A_Storage_MemcachedDriver implements Q2A_Storage_CacheDriver ...@@ -176,11 +176,16 @@ class Q2A_Storage_MemcachedDriver implements Q2A_Storage_CacheDriver
*/ */
public function getStats() public function getStats()
{ {
$stats = $this->memcached->getStats(); $totalFiles = 0;
$key = self::HOST . ':' . self::PORT; $totalBytes = 0;
$totalFiles = isset($stats[$key]['curr_items']) ? $stats[$key]['curr_items'] : 0; if ($this->enabled) {
$totalBytes = isset($stats[$key]['bytes']) ? $stats[$key]['bytes'] : 0; $stats = $this->memcached->getStats();
$key = self::HOST . ':' . self::PORT;
$totalFiles = isset($stats[$key]['curr_items']) ? $stats[$key]['curr_items'] : 0;
$totalBytes = isset($stats[$key]['bytes']) ? $stats[$key]['bytes'] : 0;
}
return array( return array(
'files' => $totalFiles, 'files' => $totalFiles,
......
...@@ -211,10 +211,7 @@ function qa_reset_options($names) ...@@ -211,10 +211,7 @@ function qa_reset_options($names)
*/ */
function qa_default_option($name) function qa_default_option($name)
{ {
if (qa_to_override(__FUNCTION__)) { if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
$args = func_get_args();
return qa_call_override(__FUNCTION__, $args);
}
$fixed_defaults = array( $fixed_defaults = array(
'allow_anonymous_naming' => 1, 'allow_anonymous_naming' => 1,
...@@ -237,6 +234,7 @@ function qa_default_option($name) ...@@ -237,6 +234,7 @@ function qa_default_option($name)
'avatar_store_size' => 400, 'avatar_store_size' => 400,
'avatar_users_size' => 30, 'avatar_users_size' => 30,
'caching_catwidget_time' => 30, 'caching_catwidget_time' => 30,
'caching_driver' => 'filesystem',
'caching_enabled' => 0, 'caching_enabled' => 0,
'caching_q_start' => 7, 'caching_q_start' => 7,
'caching_q_time' => 30, 'caching_q_time' => 30,
......
...@@ -50,6 +50,9 @@ return array( ...@@ -50,6 +50,9 @@ return array(
'block_ips_write' => 'Blocked IP addresses - separate by spaces or commas:', 'block_ips_write' => 'Blocked IP addresses - separate by spaces or commas:',
'caching_catwidget_time' => 'Cache category widget for:', 'caching_catwidget_time' => 'Cache category widget for:',
'caching_enabled' => 'Enable caching:', 'caching_enabled' => 'Enable caching:',
'caching_driver' => 'Caching driver',
'caching_filesystem' => 'Filesystem',
'caching_memcached' => 'Memcached',
'caching_q_start' => 'Start caching questions after:', 'caching_q_start' => 'Start caching questions after:',
'caching_q_time' => 'Cache question pages for:', 'caching_q_time' => 'Cache question pages for:',
'caching_qlist_time' => 'Cache question lists for:', 'caching_qlist_time' => 'Cache question lists for:',
......
...@@ -650,7 +650,7 @@ switch ($adminsection) { ...@@ -650,7 +650,7 @@ switch ($adminsection) {
$subtitle = 'admin/caching_title'; $subtitle = 'admin/caching_title';
$formstyle = 'wide'; $formstyle = 'wide';
$showoptions = array('caching_enabled', 'caching_q_start', 'caching_q_time', 'caching_qlist_time', 'caching_catwidget_time'); $showoptions = array('caching_enabled', 'caching_driver', 'caching_q_start', 'caching_q_time', 'caching_qlist_time', 'caching_catwidget_time');
break; break;
...@@ -1551,6 +1551,13 @@ foreach ($showoptions as $optionname) { ...@@ -1551,6 +1551,13 @@ foreach ($showoptions as $optionname) {
$optionfield['suffix'] = qa_lang_html('admin/emails_per_minute'); $optionfield['suffix'] = qa_lang_html('admin/emails_per_minute');
break; break;
case 'caching_driver':
qa_optionfield_make_select($optionfield, array(
'filesystem' => qa_lang_html('options/caching_filesystem'),
'memcached' => qa_lang_html('options/caching_memcached'),
), $value, 'filesystem');
break;
case 'caching_q_time': case 'caching_q_time':
case 'caching_qlist_time': case 'caching_qlist_time':
case 'caching_catwidget_time': case 'caching_catwidget_time':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment