aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Adermann <naderman@naderman.de>2011-01-12 00:28:12 +0100
committerNils Adermann <naderman@naderman.de>2011-01-12 01:47:51 +0100
commitf11579549d0250733f4a2bd1759adc2db6d587d3 (patch)
treeeebd2209f3018c83b94faebe0494c1f93c3e5ccb
parent8e26f14eb619c35cabfbf548e0d20926c4dd2d01 (diff)
downloadforums-f11579549d0250733f4a2bd1759adc2db6d587d3.tar
forums-f11579549d0250733f4a2bd1759adc2db6d587d3.tar.gz
forums-f11579549d0250733f4a2bd1759adc2db6d587d3.tar.bz2
forums-f11579549d0250733f4a2bd1759adc2db6d587d3.tar.xz
forums-f11579549d0250733f4a2bd1759adc2db6d587d3.zip
[task/config-class] Do not create multiple cache driver instances.
Retrieve the driver from the service instead of creating new ones over and over from the factory. PHPBB3-9988
-rw-r--r--phpBB/common.php4
-rw-r--r--phpBB/download/file.php4
-rw-r--r--phpBB/includes/cache/service.php65
-rw-r--r--phpBB/install/database_update.php4
-rw-r--r--phpBB/install/index.php2
-rw-r--r--phpBB/style.php4
6 files changed, 51 insertions, 32 deletions
diff --git a/phpBB/common.php b/phpBB/common.php
index 0c052ae415..0ac7cbbd86 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -207,8 +207,8 @@ $class_loader->register();
// set up caching
$cache_factory = new phpbb_cache_factory($acm_type);
-$class_loader->set_cache($cache_factory->get_driver());
$cache = $cache_factory->get_service();
+$class_loader->set_cache($cache->get_driver());
// Instantiate some basic classes
$request = new phpbb_request();
@@ -227,7 +227,7 @@ $db->sql_connect($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false, defined('
unset($dbpasswd);
// Grab global variables, re-cache if necessary
-$config = new phpbb_config_db($db, $cache_factory->get_driver(), CONFIG_TABLE);
+$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
diff --git a/phpBB/download/file.php b/phpBB/download/file.php
index 84abd3538e..a169136734 100644
--- a/phpBB/download/file.php
+++ b/phpBB/download/file.php
@@ -55,8 +55,8 @@ if (isset($_GET['avatar']))
// set up caching
$cache_factory = new phpbb_cache_factory($acm_type);
- $class_loader->set_cache($cache_factory->get_driver());
$cache = $cache_factory->get_service();
+ $class_loader->set_cache($cache->get_driver());
$db = new $sql_db();
@@ -70,7 +70,7 @@ if (isset($_GET['avatar']))
// worst-case default
$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : 'msie 6.0';
- $config = new phpbb_config_db($db, $cache_factory->get_driver(), CONFIG_TABLE);
+ $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
diff --git a/phpBB/includes/cache/service.php b/phpBB/includes/cache/service.php
index bcbb0ce872..68026c8647 100644
--- a/phpBB/includes/cache/service.php
+++ b/phpBB/includes/cache/service.php
@@ -2,7 +2,6 @@
/**
*
* @package acm
-* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
@@ -22,21 +21,41 @@ if (!defined('IN_PHPBB'))
*/
class phpbb_cache_service
{
- private $acm;
+ private $driver;
- public function __construct(phpbb_cache_driver_interface $acm = null)
+ /**
+ * Creates a cache service around a cache driver
+ *
+ * @param phpbb_cache_driver_interface $driver The cache driver
+ */
+ public function __construct(phpbb_cache_driver_interface $driver = null)
+ {
+ $this->set_driver($driver);
+ }
+
+ /**
+ * Returns the cache driver used by this cache service.
+ *
+ * @return phpbb_cache_driver_interface The cache driver
+ */
+ public function get_driver()
{
- $this->set_acm($acm);
+ return $this->driver;
}
- public function set_acm(phpbb_cache_driver_interface $acm)
+ /**
+ * Replaces the cache driver used by this cache service.
+ *
+ * @param phpbb_cache_driver_interface $driver The cache driver
+ */
+ public function set_driver(phpbb_cache_driver_interface $driver)
{
- $this->acm = $acm;
+ $this->driver = $driver;
}
public function __call($method, $arguments)
{
- return call_user_func_array(array($this->acm, $method), $arguments);
+ return call_user_func_array(array($this->driver, $method), $arguments);
}
/**
@@ -47,7 +66,7 @@ class phpbb_cache_service
{
global $db;
- if (($censors = $this->acm->get('_word_censors')) === false)
+ if (($censors = $this->driver->get('_word_censors')) === false)
{
$sql = 'SELECT word, replacement
FROM ' . WORDS_TABLE;
@@ -61,7 +80,7 @@ class phpbb_cache_service
}
$db->sql_freeresult($result);
- $this->acm->put('_word_censors', $censors);
+ $this->driver->put('_word_censors', $censors);
}
return $censors;
@@ -72,7 +91,7 @@ class phpbb_cache_service
*/
function obtain_icons()
{
- if (($icons = $this->acm->get('_icons')) === false)
+ if (($icons = $this->driver->get('_icons')) === false)
{
global $db;
@@ -92,7 +111,7 @@ class phpbb_cache_service
}
$db->sql_freeresult($result);
- $this->acm->put('_icons', $icons);
+ $this->driver->put('_icons', $icons);
}
return $icons;
@@ -103,7 +122,7 @@ class phpbb_cache_service
*/
function obtain_ranks()
{
- if (($ranks = $this->acm->get('_ranks')) === false)
+ if (($ranks = $this->driver->get('_ranks')) === false)
{
global $db;
@@ -133,7 +152,7 @@ class phpbb_cache_service
}
$db->sql_freeresult($result);
- $this->acm->put('_ranks', $ranks);
+ $this->driver->put('_ranks', $ranks);
}
return $ranks;
@@ -148,7 +167,7 @@ class phpbb_cache_service
*/
function obtain_attach_extensions($forum_id)
{
- if (($extensions = $this->acm->get('_extensions')) === false)
+ if (($extensions = $this->driver->get('_extensions')) === false)
{
global $db;
@@ -192,7 +211,7 @@ class phpbb_cache_service
}
$db->sql_freeresult($result);
- $this->acm->put('_extensions', $extensions);
+ $this->driver->put('_extensions', $extensions);
}
// Forum post
@@ -253,7 +272,7 @@ class phpbb_cache_service
*/
function obtain_bots()
{
- if (($bots = $this->acm->get('_bots')) === false)
+ if (($bots = $this->driver->get('_bots')) === false)
{
global $db;
@@ -292,7 +311,7 @@ class phpbb_cache_service
}
$db->sql_freeresult($result);
- $this->acm->put('_bots', $bots);
+ $this->driver->put('_bots', $bots);
}
return $bots;
@@ -313,7 +332,7 @@ class phpbb_cache_service
foreach ($parsed_items as $key => $parsed_array)
{
- $parsed_array = $this->acm->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
+ $parsed_array = $this->driver->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
if ($parsed_array === false)
{
@@ -339,7 +358,7 @@ class phpbb_cache_service
$parsed_array = parse_cfg_file($filename);
$parsed_array['filetime'] = @filemtime($filename);
- $this->acm->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
+ $this->driver->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
}
$parsed_items[$key] = $parsed_array;
}
@@ -352,7 +371,7 @@ class phpbb_cache_service
*/
function obtain_disallowed_usernames()
{
- if (($usernames = $this->acm->get('_disallowed_usernames')) === false)
+ if (($usernames = $this->driver->get('_disallowed_usernames')) === false)
{
global $db;
@@ -367,7 +386,7 @@ class phpbb_cache_service
}
$db->sql_freeresult($result);
- $this->acm->put('_disallowed_usernames', $usernames);
+ $this->driver->put('_disallowed_usernames', $usernames);
}
return $usernames;
@@ -380,7 +399,7 @@ class phpbb_cache_service
{
global $phpbb_root_path, $phpEx;
- if (($hook_files = $this->acm->get('_hooks')) === false)
+ if (($hook_files = $this->driver->get('_hooks')) === false)
{
$hook_files = array();
@@ -399,7 +418,7 @@ class phpbb_cache_service
closedir($dh);
}
- $this->acm->put('_hooks', $hook_files);
+ $this->driver->put('_hooks', $hook_files);
}
return $hook_files;
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 0969654084..4eedf7aa33 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -96,8 +96,8 @@ $class_loader->register();
// set up caching
$cache_factory = new phpbb_cache_factory($acm_type);
-$class_loader->set_cache($cache_factory->get_driver());
$cache = $cache_factory->get_service();
+$class_loader->set_cache($cache->get_driver());
$request = new phpbb_request();
$user = new user();
@@ -165,7 +165,7 @@ include($phpbb_root_path . 'language/' . $language . '/install.' . $phpEx);
$inline_update = (request_var('type', 0)) ? true : false;
// To let set_config() calls succeed, we need to make the config array available globally
-$config = new phpbb_config_db($db, $cache_factory->get_driver(), CONFIG_TABLE);
+$config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);
diff --git a/phpBB/install/index.php b/phpBB/install/index.php
index 18521e27d0..c8c38ba0fa 100644
--- a/phpBB/install/index.php
+++ b/phpBB/install/index.php
@@ -172,8 +172,8 @@ $class_loader->register();
// set up caching
$cache_factory = new phpbb_cache_factory('file');
-$class_loader->set_cache($cache_factory->get_driver());
$cache = $cache_factory->get_service();
+$class_loader->set_cache($cache->get_driver());
$request = new phpbb_request();
diff --git a/phpBB/style.php b/phpBB/style.php
index 88b6a54cbc..9f8b77c1f5 100644
--- a/phpBB/style.php
+++ b/phpBB/style.php
@@ -66,8 +66,8 @@ if ($id)
// set up caching
$cache_factory = new phpbb_cache_factory($acm_type);
- $class_loader->set_cache($cache_factory->get_driver());
$cache = $cache_factory->get_service();
+ $class_loader->set_cache($cache->get_driver());
$request = new phpbb_request();
$db = new $sql_db();
@@ -82,7 +82,7 @@ if ($id)
}
unset($dbpasswd);
- $config = new phpbb_config_db($db, $cache_factory->get_driver(), CONFIG_TABLE);
+ $config = new phpbb_config_db($db, $cache->get_driver(), CONFIG_TABLE);
set_config(null, null, null, $config);
set_config_count(null, null, null, $config);