aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/acm
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/acm')
-rw-r--r--phpBB/includes/acm/acm_apc.php174
-rw-r--r--phpBB/includes/acm/acm_eaccelerator.php142
-rw-r--r--phpBB/includes/acm/acm_memcache.php178
-rw-r--r--phpBB/includes/acm/acm_xcache.php133
4 files changed, 394 insertions, 233 deletions
diff --git a/phpBB/includes/acm/acm_apc.php b/phpBB/includes/acm/acm_apc.php
index e4c4b79de3..e0714b1f0a 100644
--- a/phpBB/includes/acm/acm_apc.php
+++ b/phpBB/includes/acm/acm_apc.php
@@ -1,10 +1,10 @@
<?php
-/**
+/**
*
* @package acm
* @version $Id$
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @copyright (c) 2009 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
@@ -17,32 +17,35 @@ if (!defined('IN_PHPBB'))
}
/**
-* ACM APC Based Caching
+* ACM File Based Caching
* @package acm
*/
class acm
{
- private $vars = array();
- private $is_modified = false;
+ var $vars = array();
+ var $is_modified = false;
- public $sql_rowset = array();
- public $cache_dir = '';
+ var $sql_rowset = array();
+ var $sql_row_pointer = array();
+ var $cache_dir = '';
/**
* Set cache path
*/
- function __construct()
+ function acm()
{
- $this->cache_dir = PHPBB_ROOT_PATH . 'cache/';
+ $this->cache_dir = $phpbb_root_path . 'cache/';
}
/**
* Load global cache
*/
- private function load()
+ function load()
{
// grab the global cache
- if ($this->vars = apc_fetch('global'))
+ $this->vars = apc_fetch('global');
+
+ if ($this->vars !== false)
{
return true;
}
@@ -53,20 +56,22 @@ class acm
/**
* Unload cache object
*/
- public function unload()
+ 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
*/
- private function save()
+ function save()
{
if (!$this->is_modified)
{
@@ -81,7 +86,7 @@ class acm
/**
* Tidy cache
*/
- public function tidy()
+ function tidy()
{
// cache has auto GC, no need to have any code here :)
@@ -91,28 +96,29 @@ class acm
/**
* Get saved cache object
*/
- public function get($var_name)
+ function get($var_name)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
+ if (!$this->_exists($var_name))
+ {
+ return false;
+ }
+
return apc_fetch($var_name);
}
else
{
- if (!sizeof($this->vars))
- {
- $this->load();
- }
- return (isset($this->vars[$var_name])) ? $this->vars[$var_name] : false;
+ return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
}
}
/**
* Put data into cache
*/
- public function put($var_name, $var, $ttl = 31536000)
+ function put($var_name, $var, $ttl = 31536000)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
apc_store($var_name, $var, $ttl);
}
@@ -126,7 +132,7 @@ class acm
/**
* Purge cache data
*/
- public function purge()
+ function purge()
{
// Purge all phpbb cache files
$dir = @opendir($this->cache_dir);
@@ -143,7 +149,7 @@ class acm
continue;
}
- @unlink($this->cache_dir . $entry);
+ $this->remove_file($this->cache_dir . $entry);
}
closedir($dir);
@@ -151,10 +157,11 @@ class acm
unset($this->vars);
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;
}
@@ -162,9 +169,9 @@ class acm
/**
* Destroy cache data
*/
- public function destroy($var_name, $table = '')
+ function destroy($var_name, $table = '')
{
- if ($var_name === 'sql' && !empty($table))
+ if ($var_name == 'sql' && !empty($table))
{
if (!is_array($table))
{
@@ -175,6 +182,7 @@ class acm
{
// gives us the md5s that we want
$temp = apc_fetch('sql_' . $table_name);
+
if ($temp === false)
{
continue;
@@ -193,7 +201,12 @@ class acm
return;
}
- if ($var_name[0] === '_')
+ if (!$this->_exists($var_name))
+ {
+ return;
+ }
+
+ if ($var_name[0] == '_')
{
apc_delete($var_name);
}
@@ -208,9 +221,29 @@ class acm
}
/**
+ * Check if a given cache entry exist
+ */
+ function _exists($var_name)
+ {
+ if ($var_name[0] == '_')
+ {
+ return true;
+ }
+ else
+ {
+ if (!sizeof($this->vars))
+ {
+ $this->load();
+ }
+
+ return isset($this->vars[$var_name]);
+ }
+ }
+
+ /**
* Load cached sql query
*/
- public function sql_load($query)
+ function sql_load($query)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
@@ -224,6 +257,7 @@ class acm
}
$this->sql_rowset[$query_id] = $temp;
+ $this->sql_row_pointer[$query_id] = 0;
return $query_id;
}
@@ -231,25 +265,15 @@ class acm
/**
* Save sql query
*/
- public function sql_save($query, &$query_result, $ttl)
+ function sql_save($query, &$query_result, $ttl)
{
- global $db;
-
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- // determine which tables this query belongs to:
-
- // grab all the FROM tables, avoid getting a LEFT JOIN
- preg_match('/FROM \(?(\w+(?: (?!LEFT JOIN)\w+)?(?:, ?\w+(?: (?!LEFT JOIN)\w+)?)*)\)?/', $query, $regs);
+ // determine which tables this query belongs to
+ preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs);
$tables = array_map('trim', explode(',', $regs[1]));
- // now get the LEFT JOIN
- preg_match_all('/LEFT JOIN\s+(\w+)(?: \w+)?/', $query, $result, PREG_PATTERN_ORDER);
- $tables = array_merge($tables, $result[1]);
-
- $query_hash = md5($query);
-
foreach ($tables as $table_name)
{
if (($pos = strpos($table_name, ' ')) !== false)
@@ -262,13 +286,14 @@ class acm
{
$temp = array();
}
- $temp[$query_hash] = true;
+ $temp[md5($query)] = true;
apc_store('sql_' . $table_name, $temp, $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))
{
@@ -276,35 +301,63 @@ class acm
}
$db->sql_freeresult($query_result);
- apc_store('sql_' . $query_hash, $this->sql_rowset[$query_id], $ttl);
+ apc_store('sql_' . md5($query), $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)
*/
- public function sql_fetchrow($query_id)
+ function sql_fetchrow($query_id)
{
- list(, $row) = each($this->sql_rowset[$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 ($row !== NULL) ? $row : false;
+ return false;
}
/**
* Fetch a field from the current row of a cached database result (database)
*/
- public function sql_fetchfield($query_id, $field)
+ function sql_fetchfield($query_id, $field)
{
- $row = current($this->sql_rowset[$query_id]);
+ 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 ($row !== false && isset($row[$field])) ? $row[$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)
*/
- public function sql_freeresult($query_id)
+ function sql_freeresult($query_id)
{
if (!isset($this->sql_rowset[$query_id]))
{
@@ -312,9 +365,24 @@ class acm
}
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);
+ }
}
?> \ No newline at end of file
diff --git a/phpBB/includes/acm/acm_eaccelerator.php b/phpBB/includes/acm/acm_eaccelerator.php
index 00d08f70d3..a1bc59d803 100644
--- a/phpBB/includes/acm/acm_eaccelerator.php
+++ b/phpBB/includes/acm/acm_eaccelerator.php
@@ -1,72 +1,69 @@
<?php
-/**
+/**
*
* @package acm
* @version $Id$
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
-* ACM eAccelerator Based Caching
+* ACM Memcache Based Caching
* @package acm
*/
class acm
{
- private $vars = array();
- private $is_modified = false;
+ var $vars = array();
+ var $is_modified = false;
- public $sql_rowset = array();
- public $cache_dir = '';
+ var $sql_rowset = array();
+ var $sql_row_pointer = array();
+ var $cache_dir = '';
/**
* Set cache path
*/
- function __construct()
+ function acm()
{
- $this->cache_dir = PHPBB_ROOT_PATH . 'cache/';
+ $this->cache_dir = $phpbb_root_path . 'cache/';
}
/**
* Load global cache
*/
- private function load()
+ function load()
{
// grab the global cache
- if ($this->vars = eaccelerator_get('global'))
+ $temp = eaccelerator_get('global');
+
+ if ($temp !== null)
{
- return true;
+ $this->vars = $temp;
+ }
+ else
+ {
+ return false;
}
- return false;
+ return true;
}
/**
* Unload cache object
*/
- public function unload()
+ function unload()
{
$this->save();
unset($this->vars);
unset($this->sql_rowset);
-
- $this->vars = array();
- $this->sql_rowset = array();
+ unset($this->sql_row_pointer);
}
/**
* Save modified objects
*/
- private function save()
+ function save()
{
if (!$this->is_modified)
{
@@ -81,7 +78,7 @@ class acm
/**
* Tidy cache
*/
- public function tidy()
+ function tidy()
{
eaccelerator_gc();
@@ -91,9 +88,9 @@ class acm
/**
* Get saved cache object
*/
- public function get($var_name)
+ function get($var_name)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
$temp = eaccelerator_get($var_name);
@@ -119,9 +116,9 @@ class acm
/**
* Put data into cache
*/
- public function put($var_name, $var, $ttl = 31536000)
+ function put($var_name, $var, $ttl = 31536000)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
eaccelerator_put($var_name, $var, $ttl);
}
@@ -135,7 +132,7 @@ class acm
/**
* Purge cache data
*/
- public function purge()
+ function purge()
{
// Purge all phpbb cache files
$dir = @opendir($this->cache_dir);
@@ -163,10 +160,7 @@ class acm
unset($this->vars);
unset($this->sql_rowset);
-
- $this->vars = array();
- $this->var_expires = array();
- $this->sql_rowset = array();
+ unset($this->sql_row_pointer);
$this->is_modified = false;
}
@@ -174,9 +168,9 @@ class acm
/**
* Destroy cache data
*/
- public function destroy($var_name, $table = '')
+ function destroy($var_name, $table = '')
{
- if ($var_name === 'sql' && !empty($table))
+ if ($var_name == 'sql' && !empty($table))
{
if (!is_array($table))
{
@@ -209,7 +203,7 @@ class acm
return;
}
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
eaccelerator_rm($var_name);
}
@@ -226,7 +220,7 @@ class acm
/**
* Load cached sql query
*/
- public function sql_load($query)
+ function sql_load($query)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
@@ -241,31 +235,23 @@ class acm
$this->sql_rowset[$query_id] = $temp;
+ $this->sql_row_pointer[$query_id] = 0;
+
return $query_id;
}
/**
* Save sql query
*/
- public function sql_save($query, &$query_result, $ttl)
+ function sql_save($query, &$query_result, $ttl)
{
- global $db;
-
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- // determine which tables this query belongs to:
-
- // grab all the FROM tables, avoid getting a LEFT JOIN
- preg_match('/FROM \(?(\w+(?: (?!LEFT JOIN)\w+)?(?:, ?\w+(?: (?!LEFT JOIN)\w+)?)*)\)?/', $query, $regs);
+ // determine which tables this query belongs to
+ preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs);
$tables = array_map('trim', explode(',', $regs[1]));
- // now get the LEFT JOIN
- preg_match_all('/LEFT JOIN\s+(\w+)(?: \w+)?/', $query, $result, PREG_PATTERN_ORDER);
- $tables = array_merge($tables, $result[1]);
-
- $query_hash = md5($query);
-
foreach ($tables as $table_name)
{
if (($pos = strpos($table_name, ' ')) !== false)
@@ -278,13 +264,14 @@ class acm
{
$temp = array();
}
- $temp[$query_hash] = true;
+ $temp[md5($query)] = true;
eaccelerator_put('sql_' . $table_name, $temp, $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))
{
@@ -292,35 +279,63 @@ class acm
}
$db->sql_freeresult($query_result);
- eaccelerator_put('sql_' . $query_hash, $this->sql_rowset[$query_id], $ttl);
+ eaccelerator_put('sql_' . md5($query), $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)
*/
- public function sql_fetchrow($query_id)
+ function sql_fetchrow($query_id)
{
- list(, $row) = each($this->sql_rowset[$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 ($row !== NULL) ? $row : false;
+ return false;
}
/**
* Fetch a field from the current row of a cached database result (database)
*/
- public function sql_fetchfield($query_id, $field)
+ 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)
{
- $row = current($this->sql_rowset[$query_id]);
+ if ($rownum >= sizeof($this->sql_rowset[$query_id]))
+ {
+ return false;
+ }
- return ($row !== false && isset($row[$field])) ? $row[$field] : false;
+ $this->sql_row_pointer[$query_id] = $rownum;
+ return true;
}
/**
* Free memory used for a cached database result (database)
*/
- public function sql_freeresult($query_id)
+ function sql_freeresult($query_id)
{
if (!isset($this->sql_rowset[$query_id]))
{
@@ -328,6 +343,7 @@ class acm
}
unset($this->sql_rowset[$query_id]);
+ unset($this->sql_row_pointer[$query_id]);
return true;
}
diff --git a/phpBB/includes/acm/acm_memcache.php b/phpBB/includes/acm/acm_memcache.php
index bbb556f173..a89657b04e 100644
--- a/phpBB/includes/acm/acm_memcache.php
+++ b/phpBB/includes/acm/acm_memcache.php
@@ -1,10 +1,10 @@
<?php
-/**
+/**
*
* @package acm
* @version $Id$
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
@@ -17,33 +17,38 @@ if (!defined('IN_PHPBB'))
}
/**
-* ACM Memcache Based Caching
+* ACM File Based Caching
* @package acm
*/
class acm
{
- private $vars = array();
- private $is_modified = false;
+ var $vars = array();
+ var $is_modified = false;
+
+ var $sql_rowset = array();
+ var $sql_row_pointer = array();
+ var $cache_dir = '';
- public $sql_rowset = array();
- public $cache_dir = '';
- private $memcache;
+ var $memcache;
/**
* Set cache path
*/
- function __construct()
+ function acm()
{
+ $this->cache_dir = $phpbb_root_path . 'cache/';
$this->memcache = memcache_connect('localhost', 11211);
}
/**
* Load global cache
*/
- private function load()
+ function load()
{
// grab the global cache
- if ($this->vars = memcache_get($this->memcache, 'global'))
+ $this->vars = memcache_get($this->memcache, 'global');
+
+ if ($this->vars !== false)
{
return true;
}
@@ -54,20 +59,22 @@ class acm
/**
* Unload cache object
*/
- public function unload()
+ 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
*/
- private function save()
+ function save()
{
if (!$this->is_modified)
{
@@ -82,7 +89,7 @@ class acm
/**
* Tidy cache
*/
- public function tidy()
+ function tidy()
{
// cache has auto GC, no need to have any code here :)
@@ -92,28 +99,29 @@ class acm
/**
* Get saved cache object
*/
- public function get($var_name)
+ function get($var_name)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
+ if (!$this->_exists($var_name))
+ {
+ return false;
+ }
+
return memcache_get($this->memcache, $var_name);
}
else
{
- if (!sizeof($this->vars))
- {
- $this->load();
- }
- return (isset($this->vars[$var_name])) ? $this->vars[$var_name] : false;
+ return ($this->_exists($var_name)) ? $this->vars[$var_name] : false;
}
}
/**
* Put data into cache
*/
- public function put($var_name, $var, $ttl = 31536000)
+ function put($var_name, $var, $ttl = 2592000)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
memcache_set($this->memcache, $var_name, $var, 0, $ttl);
}
@@ -127,7 +135,7 @@ class acm
/**
* Purge cache data
*/
- public function purge()
+ function purge()
{
// Purge all phpbb cache files
$dir = @opendir($this->cache_dir);
@@ -144,7 +152,7 @@ class acm
continue;
}
- @unlink($this->cache_dir . $entry);
+ $this->remove_file($this->cache_dir . $entry);
}
closedir($dir);
@@ -152,20 +160,22 @@ class acm
unset($this->vars);
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
*/
- public function destroy($var_name, $table = '')
+ function destroy($var_name, $table = '')
{
- if ($var_name === 'sql' && !empty($table))
+ if ($var_name == 'sql' && !empty($table))
{
if (!is_array($table))
{
@@ -176,6 +186,7 @@ class acm
{
// gives us the md5s that we want
$temp = memcache_get($this->memcache, 'sql_' . $table_name);
+
if ($temp === false)
{
continue;
@@ -194,7 +205,12 @@ class acm
return;
}
- if ($var_name[0] === '_')
+ if (!$this->_exists($var_name))
+ {
+ return;
+ }
+
+ if ($var_name[0] == '_')
{
memcache_delete($this->memcache, $var_name);
}
@@ -209,9 +225,29 @@ class acm
}
/**
+ * Check if a given cache entry exist
+ */
+ function _exists($var_name)
+ {
+ if ($var_name[0] == '_')
+ {
+ return true;
+ }
+ else
+ {
+ if (!sizeof($this->vars))
+ {
+ $this->load();
+ }
+
+ return isset($this->vars[$var_name]);
+ }
+ }
+
+ /**
* Load cached sql query
*/
- public function sql_load($query)
+ function sql_load($query)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
@@ -225,7 +261,7 @@ class acm
}
$this->sql_rowset[$query_id] = $temp;
-
+ $this->sql_row_pointer[$query_id] = 0;
return $query_id;
}
@@ -233,25 +269,15 @@ class acm
/**
* Save sql query
*/
- public function sql_save($query, &$query_result, $ttl)
+ function sql_save($query, &$query_result, $ttl)
{
- global $db;
-
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- // determine which tables this query belongs to:
-
- // grab all the FROM tables, avoid getting a LEFT JOIN
- preg_match('/FROM \(?(\w+(?: (?!LEFT JOIN)\w+)?(?:, ?\w+(?: (?!LEFT JOIN)\w+)?)*)\)?/', $query, $regs);
+ // determine which tables this query belongs to
+ preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs);
$tables = array_map('trim', explode(',', $regs[1]));
- // now get the LEFT JOIN
- preg_match_all('/LEFT JOIN\s+(\w+)(?: \w+)?/', $query, $result, PREG_PATTERN_ORDER);
- $tables = array_merge($tables, $result[1]);
-
- $query_hash = md5($query);
-
foreach ($tables as $table_name)
{
if (($pos = strpos($table_name, ' ')) !== false)
@@ -264,13 +290,14 @@ class acm
{
$temp = array();
}
- $temp[$query_hash] = true;
+ $temp[md5($query)] = true;
memcache_set($this->memcache, 'sql_' . $table_name, $temp, 0, $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))
{
@@ -278,35 +305,63 @@ class acm
}
$db->sql_freeresult($query_result);
- memcache_set($this->memcache, 'sql_' . $query_hash, $this->sql_rowset[$query_id], 0, $ttl);
+ memcache_set($this->memcache, 'sql_' . md5($query), $this->sql_rowset[$query_id], 0, $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)
*/
- public function sql_fetchrow($query_id)
+ function sql_fetchrow($query_id)
{
- list(, $row) = each($this->sql_rowset[$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 ($row !== NULL) ? $row : false;
+ return false;
}
/**
* Fetch a field from the current row of a cached database result (database)
*/
- public function sql_fetchfield($query_id, $field)
+ function sql_fetchfield($query_id, $field)
{
- $row = current($this->sql_rowset[$query_id]);
+ 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 ($row !== false && isset($row[$field])) ? $row[$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)
*/
- public function sql_freeresult($query_id)
+ function sql_freeresult($query_id)
{
if (!isset($this->sql_rowset[$query_id]))
{
@@ -314,9 +369,24 @@ class acm
}
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);
+ }
}
?> \ No newline at end of file
diff --git a/phpBB/includes/acm/acm_xcache.php b/phpBB/includes/acm/acm_xcache.php
index 38db4d27d8..9531f5e03d 100644
--- a/phpBB/includes/acm/acm_xcache.php
+++ b/phpBB/includes/acm/acm_xcache.php
@@ -1,45 +1,38 @@
<?php
-/**
+/**
*
* @package acm
* @version $Id$
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
-* @ignore
-*/
-if (!defined('IN_PHPBB'))
-{
- exit;
-}
-
-/**
* ACM XCache Based Caching
* @package acm
*/
class acm
{
- private $vars = array();
- private $is_modified = false;
+ var $vars = array();
+ var $is_modified = false;
- public $sql_rowset = array();
- public $cache_dir = '';
+ var $sql_rowset = array();
+ var $sql_row_pointer = array();
+ var $cache_dir = '';
/**
* Set cache path
*/
- function __construct()
+ function acm()
{
- $this->cache_dir = PHPBB_ROOT_PATH . 'cache/';
+ $this->cache_dir = $phpbb_root_path . 'cache/';
}
/**
* Load global cache
*/
- private function load()
+ function load()
{
// grab the global cache
if (xcache_isset('global'))
@@ -54,20 +47,18 @@ class acm
/**
* Unload cache object
*/
- public function unload()
+ function unload()
{
$this->save();
unset($this->vars);
unset($this->sql_rowset);
-
- $this->vars = array();
- $this->sql_rowset = array();
+ unset($this->sql_row_pointer);
}
/**
* Save modified objects
*/
- private function save()
+ function save()
{
if (!$this->is_modified)
{
@@ -82,7 +73,7 @@ class acm
/**
* Tidy cache
*/
- public function tidy()
+ function tidy()
{
// cache has auto GC, no need to have any code here :)
@@ -92,9 +83,9 @@ class acm
/**
* Get saved cache object
*/
- public function get($var_name)
+ function get($var_name)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
return (xcache_isset($var_name)) ? xcache_get($var_name) : false;
}
@@ -111,9 +102,9 @@ class acm
/**
* Put data into cache
*/
- public function put($var_name, $var, $ttl = 31536000)
+ function put($var_name, $var, $ttl = 31536000)
{
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
xcache_set($var_name, $var, $ttl);
}
@@ -127,7 +118,7 @@ class acm
/**
* Purge cache data
*/
- public function purge()
+ function purge()
{
// Purge all phpbb cache files
$dir = @opendir($this->cache_dir);
@@ -156,10 +147,7 @@ class acm
unset($this->vars);
unset($this->sql_rowset);
-
- $this->vars = array();
- $this->var_expires = array();
- $this->sql_rowset = array();
+ unset($this->sql_row_pointer);
$this->is_modified = false;
}
@@ -167,9 +155,9 @@ class acm
/**
* Destroy cache data
*/
- public function destroy($var_name, $table = '')
+ function destroy($var_name, $table = '')
{
- if ($var_name === 'sql' && !empty($table))
+ if ($var_name == 'sql' && !empty($table))
{
if (!is_array($table))
{
@@ -198,7 +186,7 @@ class acm
return;
}
- if ($var_name[0] === '_')
+ if ($var_name[0] == '_')
{
xcache_unset($var_name);
}
@@ -215,21 +203,20 @@ class acm
/**
* Load cached sql query
*/
- public function sql_load($query)
+ function sql_load($query)
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
$query_id = sizeof($this->sql_rowset);
- $query_hash = md5($query);
-
- if (!xcache_isset('sql_' . $query_hash))
+ if (!xcache_isset('sql_' . md5($query)))
{
return false;
}
- $this->sql_rowset[$query_id] = xcache_get('sql_' . $query_hash);
+ $this->sql_rowset[$query_id] = xcache_get('sql_' . md5($query));
+ $this->sql_row_pointer[$query_id] = 0;
return $query_id;
}
@@ -237,25 +224,15 @@ class acm
/**
* Save sql query
*/
- public function sql_save($query, &$query_result, $ttl)
+ function sql_save($query, &$query_result, $ttl)
{
- global $db;
-
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- // determine which tables this query belongs to:
-
- // grab all the FROM tables, avoid getting a LEFT JOIN
- preg_match('/FROM \(?(\w+(?: (?!LEFT JOIN)\w+)?(?:, ?\w+(?: (?!LEFT JOIN)\w+)?)*)\)?/', $query, $regs);
+ // determine which tables this query belongs to
+ preg_match('/FROM \\(?(\\w+(?: \\w+)?(?:, ?\\w+(?: \\w+)?)*)\\)?/', $query, $regs);
$tables = array_map('trim', explode(',', $regs[1]));
- // now get the LEFT JOIN
- preg_match_all('/LEFT JOIN\s+(\w+)(?: \w+)?/', $query, $result, PREG_PATTERN_ORDER);
- $tables = array_merge($tables, $result[1]);
-
- $query_hash = md5($query);
-
foreach ($tables as $table_name)
{
if (($pos = strpos($table_name, ' ')) !== false)
@@ -271,13 +248,14 @@ class acm
{
$temp = array();
}
- $temp[$query_hash] = true;
+ $temp[md5($query)] = true;
xcache_set('sql_' . $table_name, $temp, $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))
{
@@ -285,35 +263,63 @@ class acm
}
$db->sql_freeresult($query_result);
- xcache_set('sql_' . $query_hash, $this->sql_rowset[$query_id], $ttl);
+ xcache_set('sql_' . md5($query), $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)
*/
- public function sql_fetchrow($query_id)
+ function sql_fetchrow($query_id)
{
- list(, $row) = each($this->sql_rowset[$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 ($row !== NULL) ? $row : false;
+ return false;
}
/**
* Fetch a field from the current row of a cached database result (database)
*/
- public function sql_fetchfield($query_id, $field)
+ function sql_fetchfield($query_id, $field)
{
- $row = current($this->sql_rowset[$query_id]);
+ 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;
+ }
- return ($row !== false && isset($row[$field])) ? $row[$field] : 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)
*/
- public function sql_freeresult($query_id)
+ function sql_freeresult($query_id)
{
if (!isset($this->sql_rowset[$query_id]))
{
@@ -321,6 +327,7 @@ class acm
}
unset($this->sql_rowset[$query_id]);
+ unset($this->sql_row_pointer[$query_id]);
return true;
}