aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/acm
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2010-11-03 18:35:31 +0100
committerIgor Wiedler <igor@wiedler.ch>2011-01-09 23:49:35 +0100
commit9329b16ab13f3a4caf107df358c3c58bda2dcd8a (patch)
tree0b5faa7111c792565062c93b1c1a44eda50d4664 /phpBB/includes/acm
parent36e95f939db9b88b8519d956120d161102184ccb (diff)
downloadforums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar
forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar.gz
forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar.bz2
forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.tar.xz
forums-9329b16ab13f3a4caf107df358c3c58bda2dcd8a.zip
[task/acm-refactor] Refactor the ACM classes to have a common interface.
They are now refered to as cache drivers rather than ACM classes. The additional utility functions from the original cache class have been moved to the cache_service. The class loader is now instantiated without a cache instance and passed one as soon as it is constructed to allow autoloading the cache classes. PHPBB3-9983
Diffstat (limited to 'phpBB/includes/acm')
-rw-r--r--phpBB/includes/acm/acm_apc.php82
-rw-r--r--phpBB/includes/acm/acm_eaccelerator.php119
-rw-r--r--phpBB/includes/acm/acm_file.php730
-rw-r--r--phpBB/includes/acm/acm_memcache.php136
-rw-r--r--phpBB/includes/acm/acm_memory.php437
-rw-r--r--phpBB/includes/acm/acm_null.php154
-rw-r--r--phpBB/includes/acm/acm_xcache.php119
7 files changed, 0 insertions, 1777 deletions
diff --git a/phpBB/includes/acm/acm_apc.php b/phpBB/includes/acm/acm_apc.php
deleted file mode 100644
index ab00b43e60..0000000000
--- a/phpBB/includes/acm/acm_apc.php
+++ /dev/null
@@ -1,82 +0,0 @@
-<?php
-/**
-*
-* @package acm
-* @version $Id$
-* @copyright (c) 2005, 2009 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-// Include the abstract base
-if (!class_exists('acm_memory'))
-{
- require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
-}
-
-/**
-* ACM for APC
-* @package acm
-*/
-class acm extends acm_memory
-{
- var $extension = 'apc';
-
- /**
- * Purge cache data
- *
- * @return void
- */
- function purge()
- {
- apc_clear_cache('user');
-
- parent::purge();
- }
-
- /**
- * Fetch an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return mixed Cached data
- */
- function _read($var)
- {
- return apc_fetch($this->key_prefix . $var);
- }
-
- /**
- * Store data in the cache
- *
- * @access protected
- * @param string $var Cache key
- * @param mixed $data Data to store
- * @param int $ttl Time-to-live of cached data
- * @return bool True if the operation succeeded
- */
- function _write($var, $data, $ttl = 2592000)
- {
- return apc_store($this->key_prefix . $var, $data, $ttl);
- }
-
- /**
- * Remove an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return bool True if the operation succeeded
- */
- function _delete($var)
- {
- return apc_delete($this->key_prefix . $var);
- }
-}
diff --git a/phpBB/includes/acm/acm_eaccelerator.php b/phpBB/includes/acm/acm_eaccelerator.php
deleted file mode 100644
index 7ae1557beb..0000000000
--- a/phpBB/includes/acm/acm_eaccelerator.php
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-/**
-*
-* @package acm
-* @version $Id$
-* @copyright (c) 2005, 2009 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-// Include the abstract base
-if (!class_exists('acm_memory'))
-{
- require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
-}
-
-/**
-* ACM for eAccelerator
-* @package acm
-* @todo Missing locks from destroy() talk with David
-*/
-class acm extends acm_memory
-{
- var $extension = 'eaccelerator';
- var $function = 'eaccelerator_get';
-
- var $serialize_header = '#phpbb-serialized#';
-
- /**
- * Purge cache data
- *
- * @return void
- */
- function purge()
- {
- foreach (eaccelerator_list_keys() as $var)
- {
- // @todo Check why the substr()
- // @todo Only unset vars matching $this->key_prefix
- eaccelerator_rm(substr($var['name'], 1));
- }
-
- parent::purge();
- }
-
- /**
- * Perform cache garbage collection
- *
- * @return void
- */
- function tidy()
- {
- eaccelerator_gc();
-
- set_config('cache_last_gc', time(), true);
- }
-
- /**
- * Fetch an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return mixed Cached data
- */
- function _read($var)
- {
- $result = eaccelerator_get($this->key_prefix . $var);
-
- if ($result === null)
- {
- return false;
- }
-
- // Handle serialized objects
- if (is_string($result) && strpos($result, $this->serialize_header . 'O:') === 0)
- {
- $result = unserialize(substr($result, strlen($this->serialize_header)));
- }
-
- return $result;
- }
-
- /**
- * Store data in the cache
- *
- * @access protected
- * @param string $var Cache key
- * @param mixed $data Data to store
- * @param int $ttl Time-to-live of cached data
- * @return bool True if the operation succeeded
- */
- function _write($var, $data, $ttl = 2592000)
- {
- // Serialize objects and make them easy to detect
- $data = (is_object($data)) ? $this->serialize_header . serialize($data) : $data;
-
- return eaccelerator_put($this->key_prefix . $var, $data, $ttl);
- }
-
- /**
- * Remove an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return bool True if the operation succeeded
- */
- function _delete($var)
- {
- return eaccelerator_rm($this->key_prefix . $var);
- }
-}
diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php
deleted file mode 100644
index 0e60cd6940..0000000000
--- a/phpBB/includes/acm/acm_file.php
+++ /dev/null
@@ -1,730 +0,0 @@
-<?php
-/**
-*
-* @package acm
-* @version $Id$
-* @copyright (c) 2005, 2009 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* ACM File Based Caching
-* @package acm
-*/
-class acm
-{
- var $vars = array();
- var $var_expires = array();
- var $is_modified = false;
-
- var $sql_rowset = array();
- var $sql_row_pointer = array();
- var $cache_dir = '';
-
- /**
- * Set cache path
- */
- function acm()
- {
- global $phpbb_root_path;
- $this->cache_dir = $phpbb_root_path . 'cache/';
- }
-
- /**
- * Load global cache
- */
- function load()
- {
- return $this->_read('data_global');
- }
-
- /**
- * Unload cache object
- */
- function unload()
- {
- $this->save();
- unset($this->vars);
- unset($this->var_expires);
- unset($this->sql_rowset);
- unset($this->sql_row_pointer);
-
- $this->vars = array();
- $this->var_expires = array();
- $this->sql_rowset = array();
- $this->sql_row_pointer = array();
- }
-
- /**
- * Save modified objects
- */
- function save()
- {
- if (!$this->is_modified)
- {
- return;
- }
-
- global $phpEx;
-
- if (!$this->_write('data_global'))
- {
- if (!function_exists('phpbb_is_writable'))
- {
- global $phpbb_root_path;
- include($phpbb_root_path . 'includes/functions.' . $phpEx);
- }
-
- // Now, this occurred how often? ... phew, just tell the user then...
- if (!phpbb_is_writable($this->cache_dir))
- {
- // We need to use die() here, because else we may encounter an infinite loop (the message handler calls $cache->unload())
- die($this->cache_dir . ' is NOT writable.');
- exit;
- }
-
- die('Not able to open ' . $this->cache_dir . 'data_global.' . $phpEx);
- exit;
- }
-
- $this->is_modified = false;
- }
-
- /**
- * Tidy cache
- */
- function tidy()
- {
- global $phpEx;
-
- $dir = @opendir($this->cache_dir);
-
- if (!$dir)
- {
- return;
- }
-
- $time = time();
-
- while (($entry = readdir($dir)) !== false)
- {
- if (!preg_match('/^(sql_|data_(?!global))/', $entry))
- {
- continue;
- }
-
- if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
- {
- continue;
- }
-
- // Skip the PHP header
- fgets($handle);
-
- // Skip expiration
- $expires = (int) fgets($handle);
-
- fclose($handle);
-
- if ($time >= $expires)
- {
- $this->remove_file($this->cache_dir . $entry);
- }
- }
- closedir($dir);
-
- if (file_exists($this->cache_dir . 'data_global.' . $phpEx))
- {
- if (!sizeof($this->vars))
- {
- $this->load();
- }
-
- foreach ($this->var_expires as $var_name => $expires)
- {
- if ($time >= $expires)
- {
- $this->destroy($var_name);
- }
- }
- }
-
- set_config('cache_last_gc', time(), true);
- }
-
- /**
- * Get saved cache object
- */
- function get($var_name)
- {
- if ($var_name[0] == '_')
- {
- global $phpEx;
-
- if (!$this->_exists($var_name))
- {
- return false;
- }
-
- return $this->_read('data' . $var_name);
- }
- else
- {
- return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
- }
- }
-
- /**
- * Put data into cache
- */
- function put($var_name, $var, $ttl = 31536000)
- {
- if ($var_name[0] == '_')
- {
- $this->_write('data' . $var_name, $var, time() + $ttl);
- }
- else
- {
- $this->vars[$var_name] = $var;
- $this->var_expires[$var_name] = time() + $ttl;
- $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, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
- {
- continue;
- }
-
- $this->remove_file($this->cache_dir . $entry);
- }
- closedir($dir);
-
- unset($this->vars);
- unset($this->var_expires);
- unset($this->sql_rowset);
- unset($this->sql_row_pointer);
-
- $this->vars = array();
- $this->var_expires = array();
- $this->sql_rowset = array();
- $this->sql_row_pointer = array();
-
- $this->is_modified = false;
- }
-
- /**
- * Destroy cache data
- */
- function destroy($var_name, $table = '')
- {
- global $phpEx;
-
- if ($var_name == 'sql' && !empty($table))
- {
- if (!is_array($table))
- {
- $table = array($table);
- }
-
- $dir = @opendir($this->cache_dir);
-
- if (!$dir)
- {
- return;
- }
-
- while (($entry = readdir($dir)) !== false)
- {
- if (strpos($entry, 'sql_') !== 0)
- {
- continue;
- }
-
- if (!($handle = @fopen($this->cache_dir . $entry, 'rb')))
- {
- continue;
- }
-
- // Skip the PHP header
- fgets($handle);
-
- // Skip expiration
- fgets($handle);
-
- // Grab the query, remove the LF
- $query = substr(fgets($handle), 0, -1);
-
- fclose($handle);
-
- foreach ($table as $check_table)
- {
- // Better catch partial table names than no table names. ;)
- if (strpos($query, $check_table) !== false)
- {
- $this->remove_file($this->cache_dir . $entry);
- break;
- }
- }
- }
- closedir($dir);
-
- return;
- }
-
- if (!$this->_exists($var_name))
- {
- return;
- }
-
- if ($var_name[0] == '_')
- {
- $this->remove_file($this->cache_dir . 'data' . $var_name . ".$phpEx", true);
- }
- else if (isset($this->vars[$var_name]))
- {
- $this->is_modified = true;
- unset($this->vars[$var_name]);
- unset($this->var_expires[$var_name]);
-
- // We save here to let the following cache hits succeed
- $this->save();
- }
- }
-
- /**
- * Check if a given cache entry exist
- */
- function _exists($var_name)
- {
- if ($var_name[0] == '_')
- {
- global $phpEx;
- return file_exists($this->cache_dir . 'data' . $var_name . ".$phpEx");
- }
- else
- {
- if (!sizeof($this->vars))
- {
- $this->load();
- }
-
- if (!isset($this->var_expires[$var_name]))
- {
- return false;
- }
-
- return (time() > $this->var_expires[$var_name]) ? false : isset($this->vars[$var_name]);
- }
- }
-
- /**
- * Load cached sql query
- */
- function sql_load($query)
- {
- // Remove extra spaces and tabs
- $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
-
- if (($rowset = $this->_read('sql_' . md5($query))) === false)
- {
- return false;
- }
-
- $query_id = sizeof($this->sql_rowset);
- $this->sql_rowset[$query_id] = $rowset;
- $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);
-
- $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);
-
- if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query))
- {
- $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;
- }
-
- /**
- * Read cached data from a specified file
- *
- * @access private
- * @param string $filename Filename to write
- * @return mixed False if an error was encountered, otherwise the data type of the cached data
- */
- function _read($filename)
- {
- global $phpEx;
-
- $file = "{$this->cache_dir}$filename.$phpEx";
-
- $type = substr($filename, 0, strpos($filename, '_'));
-
- if (!file_exists($file))
- {
- return false;
- }
-
- if (!($handle = @fopen($file, 'rb')))
- {
- return false;
- }
-
- // Skip the PHP header
- fgets($handle);
-
- if ($filename == 'data_global')
- {
- $this->vars = $this->var_expires = array();
-
- $time = time();
-
- while (($expires = (int) fgets($handle)) && !feof($handle))
- {
- // Number of bytes of data
- $bytes = substr(fgets($handle), 0, -1);
-
- if (!is_numeric($bytes) || ($bytes = (int) $bytes) === 0)
- {
- // We cannot process the file without a valid number of bytes
- // so we discard it
- fclose($handle);
-
- $this->vars = $this->var_expires = array();
- $this->is_modified = false;
-
- $this->remove_file($file);
-
- return false;
- }
-
- if ($time >= $expires)
- {
- fseek($handle, $bytes, SEEK_CUR);
-
- continue;
- }
-
- $var_name = substr(fgets($handle), 0, -1);
-
- // Read the length of bytes that consists of data.
- $data = fread($handle, $bytes - strlen($var_name));
- $data = @unserialize($data);
-
- // Don't use the data if it was invalid
- if ($data !== false)
- {
- $this->vars[$var_name] = $data;
- $this->var_expires[$var_name] = $expires;
- }
-
- // Absorb the LF
- fgets($handle);
- }
-
- fclose($handle);
-
- $this->is_modified = false;
-
- return true;
- }
- else
- {
- $data = false;
- $line = 0;
-
- while (($buffer = fgets($handle)) && !feof($handle))
- {
- $buffer = substr($buffer, 0, -1); // Remove the LF
-
- // $buffer is only used to read integers
- // if it is non numeric we have an invalid
- // cache file, which we will now remove.
- if (!is_numeric($buffer))
- {
- break;
- }
-
- if ($line == 0)
- {
- $expires = (int) $buffer;
-
- if (time() >= $expires)
- {
- break;
- }
-
- if ($type == 'sql')
- {
- // Skip the query
- fgets($handle);
- }
- }
- else if ($line == 1)
- {
- $bytes = (int) $buffer;
-
- // Never should have 0 bytes
- if (!$bytes)
- {
- break;
- }
-
- // Grab the serialized data
- $data = fread($handle, $bytes);
-
- // Read 1 byte, to trigger EOF
- fread($handle, 1);
-
- if (!feof($handle))
- {
- // Somebody tampered with our data
- $data = false;
- }
- break;
- }
- else
- {
- // Something went wrong
- break;
- }
- $line++;
- }
- fclose($handle);
-
- // unserialize if we got some data
- $data = ($data !== false) ? @unserialize($data) : $data;
-
- if ($data === false)
- {
- $this->remove_file($file);
- return false;
- }
-
- return $data;
- }
- }
-
- /**
- * Write cache data to a specified file
- *
- * 'data_global' is a special case and the generated format is different for this file:
- * <code>
- * <?php exit; ?>
- * (expiration)
- * (length of var and serialised data)
- * (var)
- * (serialised data)
- * ... (repeat)
- * </code>
- *
- * The other files have a similar format:
- * <code>
- * <?php exit; ?>
- * (expiration)
- * (query) [SQL files only]
- * (length of serialised data)
- * (serialised data)
- * </code>
- *
- * @access private
- * @param string $filename Filename to write
- * @param mixed $data Data to store
- * @param int $expires Timestamp when the data expires
- * @param string $query Query when caching SQL queries
- * @return bool True if the file was successfully created, otherwise false
- */
- function _write($filename, $data = null, $expires = 0, $query = '')
- {
- global $phpEx;
-
- $file = "{$this->cache_dir}$filename.$phpEx";
-
- if ($handle = @fopen($file, 'wb'))
- {
- @flock($handle, LOCK_EX);
-
- // File header
- fwrite($handle, '<' . '?php exit; ?' . '>');
-
- if ($filename == 'data_global')
- {
- // Global data is a different format
- foreach ($this->vars as $var => $data)
- {
- if (strpos($var, "\r") !== false || strpos($var, "\n") !== false)
- {
- // CR/LF would cause fgets() to read the cache file incorrectly
- // do not cache test entries, they probably won't be read back
- // the cache keys should really be alphanumeric with a few symbols.
- continue;
- }
- $data = serialize($data);
-
- // Write out the expiration time
- fwrite($handle, "\n" . $this->var_expires[$var] . "\n");
-
- // Length of the remaining data for this var (ignoring two LF's)
- fwrite($handle, strlen($data . $var) . "\n");
- fwrite($handle, $var . "\n");
- fwrite($handle, $data);
- }
- }
- else
- {
- fwrite($handle, "\n" . $expires . "\n");
-
- if (strpos($filename, 'sql_') === 0)
- {
- fwrite($handle, $query . "\n");
- }
- $data = serialize($data);
-
- fwrite($handle, strlen($data) . "\n");
- fwrite($handle, $data);
- }
-
- @flock($handle, LOCK_UN);
- fclose($handle);
-
- if (!function_exists('phpbb_chmod'))
- {
- global $phpbb_root_path;
- include($phpbb_root_path . 'includes/functions.' . $phpEx);
- }
-
- phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Removes/unlinks file
- */
- function remove_file($filename, $check = false)
- {
- if (!function_exists('phpbb_is_writable'))
- {
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/functions.' . $phpEx);
- }
-
- if ($check && !phpbb_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);
- }
-}
diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php
deleted file mode 100644
index 527db71f80..0000000000
--- a/phpBB/includes/acm/acm_memcache.php
+++ /dev/null
@@ -1,136 +0,0 @@
-<?php
-/**
-*
-* @package acm
-* @version $Id$
-* @copyright (c) 2005, 2009 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-// 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);
-}
-
-if (!defined('PHPBB_ACM_MEMCACHE_COMPRESS'))
-{
- define('PHPBB_ACM_MEMCACHE_COMPRESS', false);
-}
-
-if (!defined('PHPBB_ACM_MEMCACHE_HOST'))
-{
- define('PHPBB_ACM_MEMCACHE_HOST', 'localhost');
-}
-
-if (!defined('PHPBB_ACM_MEMCACHE'))
-{
- //can define multiple servers with host1/port1,host2/port2 format
- define('PHPBB_ACM_MEMCACHE', PHPBB_ACM_MEMCACHE_HOST . '/' . PHPBB_ACM_MEMCACHE_PORT);
-}
-
-/**
-* ACM for Memcached
-* @package acm
-*/
-class acm extends acm_memory
-{
- var $extension = 'memcache';
-
- var $memcache;
- var $flags = 0;
-
- function acm()
- {
- // Call the parent constructor
- parent::acm_memory();
-
- $this->memcache = new Memcache;
- foreach(explode(',', PHPBB_ACM_MEMCACHE) as $u)
- {
- $parts = explode('/', $u);
- $this->memcache->addServer(trim($parts[0]), trim($parts[1]));
- }
- $this->flags = (PHPBB_ACM_MEMCACHE_COMPRESS) ? MEMCACHE_COMPRESSED : 0;
- }
-
- /**
- * Unload the cache resources
- *
- * @return void
- */
- function unload()
- {
- parent::unload();
-
- $this->memcache->close();
- }
-
- /**
- * Purge cache data
- *
- * @return void
- */
- function purge()
- {
- $this->memcache->flush();
-
- parent::purge();
- }
-
- /**
- * Fetch an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return mixed Cached data
- */
- function _read($var)
- {
- return $this->memcache->get($this->key_prefix . $var);
- }
-
- /**
- * Store data in the cache
- *
- * @access protected
- * @param string $var Cache key
- * @param mixed $data Data to store
- * @param int $ttl Time-to-live of cached data
- * @return bool True if the operation succeeded
- */
- function _write($var, $data, $ttl = 2592000)
- {
- if (!$this->memcache->replace($this->key_prefix . $var, $data, $this->flags, $ttl))
- {
- return $this->memcache->set($this->key_prefix . $var, $data, $this->flags, $ttl);
- }
- return true;
- }
-
- /**
- * Remove an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return bool True if the operation succeeded
- */
- function _delete($var)
- {
- return $this->memcache->delete($this->key_prefix . $var);
- }
-}
diff --git a/phpBB/includes/acm/acm_memory.php b/phpBB/includes/acm/acm_memory.php
deleted file mode 100644
index d248487846..0000000000
--- a/phpBB/includes/acm/acm_memory.php
+++ /dev/null
@@ -1,437 +0,0 @@
-<?php
-/**
-*
-* @package acm
-* @version $Id$
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* ACM Abstract Memory Class
-* @package acm
-*/
-class acm_memory
-{
- var $key_prefix;
-
- var $vars = array();
- var $is_modified = false;
-
- var $sql_rowset = array();
- var $sql_row_pointer = array();
- var $cache_dir = '';
-
- /**
- * Set cache path
- */
- function acm_memory()
- {
- global $phpbb_root_path, $dbname, $table_prefix;
-
- $this->cache_dir = $phpbb_root_path . 'cache/';
- $this->key_prefix = substr(md5($dbname . $table_prefix), 0, 8) . '_';
-
- if (!isset($this->extension) || !extension_loaded($this->extension))
- {
- global $acm_type;
-
- trigger_error("Could not find required extension [{$this->extension}] for the ACM module $acm_type.", E_USER_ERROR);
- }
-
- if (isset($this->function) && !function_exists($this->function))
- {
- global $acm_type;
-
- trigger_error("The required function [{$this->function}] is not available for the ACM module $acm_type.", E_USER_ERROR);
- }
- }
-
- /**
- * Load global cache
- */
- function load()
- {
- // grab the global cache
- $this->vars = $this->_read('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();
- }
-
- /**
- * Save modified objects
- */
- function save()
- {
- if (!$this->is_modified)
- {
- return;
- }
-
- $this->_write('global', $this->vars, 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] == '_')
- {
- if (!$this->_exists($var_name))
- {
- return false;
- }
-
- return $this->_read($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->_write($var_name, $var, $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, 'sql_') !== 0 && strpos($entry, 'data_') !== 0 && strpos($entry, 'ctpl_') !== 0 && strpos($entry, 'tpl_') !== 0)
- {
- continue;
- }
-
- $this->remove_file($this->cache_dir . $entry);
- }
- closedir($dir);
-
- 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;
- }
-
-
- /**
- * Destroy cache data
- */
- function destroy($var_name, $table = '')
- {
- 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->_read('sql_' . $table_name);
-
- if ($temp === false)
- {
- continue;
- }
-
- // delete each query ref
- foreach ($temp as $md5_id => $void)
- {
- $this->_delete('sql_' . $md5_id);
- }
-
- // delete the table ref
- $this->_delete('sql_' . $table_name);
- }
-
- return;
- }
-
- if (!$this->_exists($var_name))
- {
- return;
- }
-
- if ($var_name[0] == '_')
- {
- $this->_delete($var_name);
- }
- else if (isset($this->vars[$var_name]))
- {
- $this->is_modified = true;
- unset($this->vars[$var_name]);
-
- // We save here to let the following cache hits succeed
- $this->save();
- }
- }
-
- /**
- * Check if a given cache entry exist
- */
- function _exists($var_name)
- {
- if ($var_name[0] == '_')
- {
- return $this->_isset($var_name);
- }
- else
- {
- if (!sizeof($this->vars))
- {
- $this->load();
- }
-
- return isset($this->vars[$var_name]);
- }
- }
-
- /**
- * Load cached sql query
- */
- function sql_load($query)
- {
- // Remove extra spaces and tabs
- $query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- $query_id = sizeof($this->sql_rowset);
-
- if (($result = $this->_read('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
- // Some queries use backticks, namely the get_database_size() query
- // don't check for conformity, the SQL would error and not reach here.
- if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs))
- {
- // Bail out if the match fails.
- return;
- }
- $tables = array_map('trim', explode(',', $regs[1]));
-
- foreach ($tables as $table_name)
- {
- // Remove backticks
- $table_name = ($table_name[0] == '`') ? substr($table_name, 1, -1) : $table_name;
-
- if (($pos = strpos($table_name, ' ')) !== false)
- {
- $table_name = substr($table_name, 0, $pos);
- }
-
- $temp = $this->_read('sql_' . $table_name);
-
- if ($temp === false)
- {
- $temp = array();
- }
-
- $temp[$hash] = true;
-
- // This must never expire
- $this->_write('sql_' . $table_name, $temp, 0);
- }
-
- // 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->_write('sql_' . $hash, $this->sql_rowset[$query_id], $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 (!function_exists('phpbb_is_writable'))
- {
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/functions.' . $phpEx);
- }
-
- if ($check && !phpbb_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);
- }
-
- /**
- * Check if a cache var exists
- *
- * @access protected
- * @param string $var Cache key
- * @return bool True if it exists, otherwise false
- */
- function _isset($var)
- {
- // Most caches don't need to check
- return true;
- }
-}
diff --git a/phpBB/includes/acm/acm_null.php b/phpBB/includes/acm/acm_null.php
deleted file mode 100644
index 79f2b59c0f..0000000000
--- a/phpBB/includes/acm/acm_null.php
+++ /dev/null
@@ -1,154 +0,0 @@
-<?php
-/**
-*
-* @package acm
-* @version $Id$
-* @copyright (c) 2005, 2009 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* ACM Null Caching
-* @package acm
-*/
-class acm
-{
- /**
- * Set cache path
- */
- function acm()
- {
- }
-
- /**
- * Load global cache
- */
- function load()
- {
- return true;
- }
-
- /**
- * Unload cache object
- */
- function unload()
- {
- }
-
- /**
- * Save modified objects
- */
- function save()
- {
- }
-
- /**
- * Tidy cache
- */
- function tidy()
- {
- // This cache always has a tidy room.
- set_config('cache_last_gc', time(), true);
- }
-
- /**
- * Get saved cache object
- */
- function get($var_name)
- {
- return false;
- }
-
- /**
- * Put data into cache
- */
- function put($var_name, $var, $ttl = 0)
- {
- }
-
- /**
- * Purge cache data
- */
- function purge()
- {
- }
-
- /**
- * Destroy cache data
- */
- function destroy($var_name, $table = '')
- {
- }
-
- /**
- * Check if a given cache entry exist
- */
- function _exists($var_name)
- {
- return false;
- }
-
- /**
- * Load cached sql query
- */
- function sql_load($query)
- {
- return false;
- }
-
- /**
- * Save sql query
- */
- function sql_save($query, &$query_result, $ttl)
- {
- }
-
- /**
- * Ceck if a given sql query exist in cache
- */
- function sql_exists($query_id)
- {
- return false;
- }
-
- /**
- * Fetch row from cache (database)
- */
- function sql_fetchrow($query_id)
- {
- return false;
- }
-
- /**
- * Fetch a field from the current row of a cached database result (database)
- */
- function sql_fetchfield($query_id, $field)
- {
- return false;
- }
-
- /**
- * Seek a specific row in an a cached database result (database)
- */
- function sql_rowseek($rownum, $query_id)
- {
- return false;
- }
-
- /**
- * Free memory used for a cached database result (database)
- */
- function sql_freeresult($query_id)
- {
- return false;
- }
-}
diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php
deleted file mode 100644
index 8be0ad0c48..0000000000
--- a/phpBB/includes/acm/acm_xcache.php
+++ /dev/null
@@ -1,119 +0,0 @@
-<?php
-/**
-*
-* @package acm
-* @version $Id$
-* @copyright (c) 2005, 2009 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
-*
-*/
-
-/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-// Include the abstract base
-if (!class_exists('acm_memory'))
-{
- require("{$phpbb_root_path}includes/acm/acm_memory.$phpEx");
-}
-
-/**
-* ACM for XCache
-* @package acm
-*
-* To use this module you need ini_get() enabled and the following INI settings configured as follows:
-* - xcache.var_size > 0
-* - xcache.admin.enable_auth = off (or xcache.admin.user and xcache.admin.password set)
-*
-*/
-class acm extends acm_memory
-{
- var $extension = 'XCache';
-
- function acm()
- {
- parent::acm_memory();
-
- if (!function_exists('ini_get') || (int) ini_get('xcache.var_size') <= 0)
- {
- trigger_error('Increase xcache.var_size setting above 0 or enable ini_get() to use this ACM module.', E_USER_ERROR);
- }
- }
-
- /**
- * Purge cache data
- *
- * @return void
- */
- function purge()
- {
- // Run before for XCache, if admin functions are disabled it will terminate execution
- parent::purge();
-
- // If the admin authentication is enabled but not set up, this will cause a nasty error.
- // Not much we can do about it though.
- $n = xcache_count(XC_TYPE_VAR);
-
- for ($i = 0; $i < $n; $i++)
- {
- xcache_clear_cache(XC_TYPE_VAR, $i);
- }
- }
-
- /**
- * Fetch an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return mixed Cached data
- */
- function _read($var)
- {
- $result = xcache_get($this->key_prefix . $var);
-
- return ($result !== null) ? $result : false;
- }
-
- /**
- * Store data in the cache
- *
- * @access protected
- * @param string $var Cache key
- * @param mixed $data Data to store
- * @param int $ttl Time-to-live of cached data
- * @return bool True if the operation succeeded
- */
- function _write($var, $data, $ttl = 2592000)
- {
- return xcache_set($this->key_prefix . $var, $data, $ttl);
- }
-
- /**
- * Remove an item from the cache
- *
- * @access protected
- * @param string $var Cache key
- * @return bool True if the operation succeeded
- */
- function _delete($var)
- {
- return xcache_unset($this->key_prefix . $var);
- }
-
- /**
- * Check if a cache var exists
- *
- * @access protected
- * @param string $var Cache key
- * @return bool True if it exists, otherwise false
- */
- function _isset($var)
- {
- return xcache_isset($this->key_prefix . $var);
- }
-}