diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index 90ff74a2b1..69ae879ebb 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -92,7 +92,7 @@
[Fix] Sorting by author or subject on viewtopic now preserves the order. (Bug #44875)
[Fix] Correctly determine writable status of files on Windows operating system. (Bug #39035)
[Feature] Backported 3.2 captcha plugins.
- [Feature] Introduced new ACM plugins: null, memcache.
+ [Feature] Introduced new ACM plugins: null, memcache, APC.
1.ii. Changes since 3.0.4
diff --git a/phpBB/includes/acm/acm_apc.php b/phpBB/includes/acm/acm_apc.php
new file mode 100644
index 0000000000..409854bc26
--- /dev/null
+++ b/phpBB/includes/acm/acm_apc.php
@@ -0,0 +1,63 @@
+
\ No newline at end of file
diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php
index 1fe9218104..4950738522 100644
--- a/phpBB/includes/acm/acm_memcache.php
+++ b/phpBB/includes/acm/acm_memcache.php
@@ -3,7 +3,7 @@
*
* @package acm
* @version $Id$
-* @copyright (c) 2005 phpBB Group
+* @copyright (c) 2005, 2009 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
@@ -26,6 +26,12 @@ if (!extension_loaded('memcache') || !defined('PHPBB_ACM_MEMCACHE_HOST'))
return;
}
+// Include the abstract base
+if (!class_exists('acm_memory'))
+{
+ require("${phpbb_root_path}includes/acm/acm_memory.$phpEx");
+}
+
if (!defined('PHPBB_ACM_MEMCACHE_PORT'))
{
define('PHPBB_ACM_MEMCACHE_PORT', 11211);
@@ -40,379 +46,51 @@ if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS'))
* ACM for Memcached
* @package acm
*/
-class acm
+class acm extends acm_memory
{
- var $vars = array();
- var $is_modified = false;
-
- var $sql_rowset = array();
- var $sql_row_pointer = array();
- var $cache_dir = '';
-
var $memcache;
var $flags = 0;
- /**
- * Set cache path
- */
function acm()
{
- global $phpbb_root_path;
+ // Call the parent constructor
+ parent::acm_memory();
$this->memcache = new Memcache;
$this->memcache->connect(PHPBB_ACM_MEMCACHE_HOST, PHPBB_ACM_MEMCACHE_PORT);
$this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0;
-
- $this->cache_dir = $phpbb_root_path . 'cache/';
}
- /**
- * Load global cache
- */
- function load()
- {
- // grab the global cache
- $this->vars = $this->memcache->get('global');
-
- if ($this->vars !== false)
- {
- return true;
- }
-
- return false;
- }
-
- /**
- * Unload cache object
- */
function unload()
{
- $this->save();
- unset($this->vars);
- unset($this->sql_rowset);
- unset($this->sql_row_pointer);
-
- $this->vars = array();
- $this->sql_rowset = array();
- $this->sql_row_pointer = array();
+ parent::unload();
$this->memcache->close();
}
- /**
- * Save modified objects
- */
- function save()
- {
- if (!$this->is_modified)
- {
- return;
- }
-
- $this->memcache->set('global', $this->vars, $this->flags, 2592000);
-
- $this->is_modified = false;
- }
-
- /**
- * Tidy cache
- */
- function tidy()
- {
- // cache has auto GC, no need to have any code here :)
-
- set_config('cache_last_gc', time(), true);
- }
-
- /**
- * Get saved cache object
- */
- function get($var_name)
- {
- if ($var_name[0] == '_')
- {
- return $this->memcache->get($var_name);
- }
- else
- {
- return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
- }
- }
-
- /**
- * Put data into cache
- */
- function put($var_name, $var, $ttl = 2592000)
- {
- if ($var_name[0] == '_')
- {
- $this->memcache->set($var_name, $var, $this->flags, $ttl);
- }
- else
- {
- $this->vars[$var_name] = $var;
- $this->is_modified = true;
- }
- }
-
/**
* Purge cache data
*/
function purge()
{
- // Purge all phpbb cache files
- $dir = @opendir($this->cache_dir);
-
- if (!$dir)
- {
- return;
- }
-
- while (($entry = readdir($dir)) !== false)
- {
- if (strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
- {
- continue;
- }
-
- $this->remove_file($this->cache_dir . $entry);
- }
- closedir($dir);
-
$this->memcache->flush();
- unset($this->vars);
- unset($this->sql_rowset);
- unset($this->sql_row_pointer);
-
- $this->vars = array();
- $this->sql_rowset = array();
- $this->sql_row_pointer = array();
-
- $this->is_modified = false;
+ parent::purge();
}
-
- /**
- * Destroy cache data
- */
- function destroy($var_name, $table = '')
+ function read($var)
{
- if ($var_name == 'sql' && !empty($table))
- {
- if (!is_array($table))
- {
- $table = array($table);
- }
-
- foreach ($table as $table_name)
- {
- // gives us the md5s that we want
- $temp = $this->memcache->get('sql_' . $table_name);
-
- if ($temp === false)
- {
- continue;
- }
-
- // delete each query ref
- foreach ($temp as $md5_id => $void)
- {
- $this->memcache->delete('sql_' . $md5_id);
- }
-
- // delete the table ref
- $this->memcache->delete('sql_' . $table_name);
- }
-
- return;
- }
-
- if (!$this->_exists($var_name))
- {
- return;
- }
-
- if ($var_name[0] == '_')
- {
- $this->memcache->delete($var_name);
- }
- else
- {
- $this->is_modified = true;
- unset($this->vars[$var_name]);
-
- // We save here to let the following cache hits succeed
- $this->save();
- }
+ return $this->memcache->get($var);
}
- /**
- * Check if a given cache entry exist
- */
- function _exists($var_name)
+ function write($var, $data, $ttl = 2592000)
{
- if ($var_name[0] == '_')
- {
- return true;
- }
- else
- {
- if (!sizeof($this->vars))
- {
- $this->load();
- }
-
- return isset($this->vars[$var_name]);
- }
+ return $this->memcache->set($var, $data, $this->flags, $ttl);
}
- /**
- * Load cached sql query
- */
- function sql_load($query)
+ function delete($var)
{
- // Remove extra spaces and tabs
- $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- $query_id = sizeof($this->sql_rowset);
-
- if (($result = $this->memcache->get('sql_' . md5($query))) === false)
- {
- return false;
- }
-
- $this->sql_rowset[$query_id] = $result;
- $this->sql_row_pointer[$query_id] = 0;
-
- return $query_id;
- }
-
- /**
- * Save sql query
- */
- function sql_save($query, &$query_result, $ttl)
- {
- global $db;
-
- // Remove extra spaces and tabs
- $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- $hash = md5($query);
-
- // determine which tables this query belongs to
- preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs);
- $tables = array_map('trim', explode(',', $regs[1]));
-
- foreach ($tables as $table_name)
- {
- if (($pos = strpos($table_name, ' ')) !== false)
- {
- $table_name = substr($table_name, 0, $pos);
- }
-
- $temp = $this->memcache->get('sql_' . $table_name);
-
- if ($temp === false)
- {
- $temp = array();
- }
-
- $temp[$hash] = true;
-
- $this->memcache->set('sql_' . $table_name, $temp, $this->flags, $ttl);
- }
-
- // store them in the right place
- $query_id = sizeof($this->sql_rowset);
- $this->sql_rowset[$query_id] = array();
- $this->sql_row_pointer[$query_id] = 0;
-
- while ($row = $db->sql_fetchrow($query_result))
- {
- $this->sql_rowset[$query_id][] = $row;
- }
- $db->sql_freeresult($query_result);
-
- $this->memcache->set('sql_' . $hash, $this->sql_rowset[$query_id], $this->flags, $ttl);
-
- $query_result = $query_id;
- }
-
- /**
- * Ceck if a given sql query exist in cache
- */
- function sql_exists($query_id)
- {
- return isset($this->sql_rowset[$query_id]);
- }
-
- /**
- * Fetch row from cache (database)
- */
- function sql_fetchrow($query_id)
- {
- if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
- {
- return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
- }
-
- return false;
- }
-
- /**
- * Fetch a field from the current row of a cached database result (database)
- */
- function sql_fetchfield($query_id, $field)
- {
- if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
- {
- return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field] : false;
- }
-
- return false;
- }
-
- /**
- * Seek a specific row in an a cached database result (database)
- */
- function sql_rowseek($rownum, $query_id)
- {
- if ($rownum >= sizeof($this->sql_rowset[$query_id]))
- {
- return false;
- }
-
- $this->sql_row_pointer[$query_id] = $rownum;
- return true;
- }
-
- /**
- * Free memory used for a cached database result (database)
- */
- function sql_freeresult($query_id)
- {
- if (!isset($this->sql_rowset[$query_id]))
- {
- return false;
- }
-
- unset($this->sql_rowset[$query_id]);
- unset($this->sql_row_pointer[$query_id]);
-
- return true;
- }
-
- /**
- * Removes/unlinks file
- */
- function remove_file($filename, $check = false)
- {
- if ($check && !@is_writable($this->cache_dir))
- {
- // E_USER_ERROR - not using language entry - intended.
- trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR);
- }
-
- return @unlink($filename);
+ return $this->memcache->delete($var);
}
}