aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/cache/driver
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/phpbb/cache/driver')
-rw-r--r--phpBB/phpbb/cache/driver/apcu.php74
-rw-r--r--phpBB/phpbb/cache/driver/base.php22
-rw-r--r--phpBB/phpbb/cache/driver/dummy.php (renamed from phpBB/phpbb/cache/driver/null.php)8
-rw-r--r--phpBB/phpbb/cache/driver/eaccelerator.php4
-rw-r--r--phpBB/phpbb/cache/driver/file.php47
-rw-r--r--phpBB/phpbb/cache/driver/memcached.php4
-rw-r--r--phpBB/phpbb/cache/driver/memory.php23
-rw-r--r--phpBB/phpbb/cache/driver/redis.php4
8 files changed, 137 insertions, 49 deletions
diff --git a/phpBB/phpbb/cache/driver/apcu.php b/phpBB/phpbb/cache/driver/apcu.php
new file mode 100644
index 0000000000..c96cf0de57
--- /dev/null
+++ b/phpBB/phpbb/cache/driver/apcu.php
@@ -0,0 +1,74 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\cache\driver;
+
+/**
+* ACM for APCU
+*/
+class apcu extends \phpbb\cache\driver\memory
+{
+ var $extension = 'apcu';
+
+ /**
+ * {@inheritDoc}
+ */
+ function purge()
+ {
+ /*
+ * Use an iterator to selectively delete our cache entries without disturbing
+ * any other cache users (e.g. other phpBB boards hosted on this server)
+ */
+ apcu_delete(new \APCUIterator('#^' . $this->key_prefix . '#'));
+
+ parent::purge();
+ }
+
+ /**
+ * Fetch an item from the cache
+ *
+ * @access protected
+ * @param string $var Cache key
+ * @return mixed Cached data
+ */
+ function _read($var)
+ {
+ return apcu_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 apcu_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 apcu_delete($this->key_prefix . $var);
+ }
+}
diff --git a/phpBB/phpbb/cache/driver/base.php b/phpBB/phpbb/cache/driver/base.php
index 53c50eeda3..3eca521148 100644
--- a/phpBB/phpbb/cache/driver/base.php
+++ b/phpBB/phpbb/cache/driver/base.php
@@ -49,7 +49,9 @@ abstract class base implements \phpbb\cache\driver\driver_interface
$this->remove_dir($fileInfo->getPathname());
}
else if (strpos($filename, 'container_') === 0 ||
+ strpos($filename, 'autoload_') === 0 ||
strpos($filename, 'url_matcher') === 0 ||
+ strpos($filename, 'url_generator') === 0 ||
strpos($filename, 'sql_') === 0 ||
strpos($filename, 'data_') === 0)
{
@@ -95,14 +97,14 @@ abstract class base implements \phpbb\cache\driver\driver_interface
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
+ $query_id = md5($query);
- if (($rowset = $this->_read('sql_' . md5($query))) === false)
+ if (($result = $this->_read('sql_' . $query_id)) === false)
{
return false;
}
- $query_id = sizeof($this->sql_rowset);
- $this->sql_rowset[$query_id] = $rowset;
+ $this->sql_rowset[$query_id] = $result;
$this->sql_row_pointer[$query_id] = 0;
return $query_id;
@@ -121,7 +123,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
*/
function sql_fetchrow($query_id)
{
- if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
+ if ($this->sql_row_pointer[$query_id] < count($this->sql_rowset[$query_id]))
{
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++];
}
@@ -134,7 +136,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
*/
function sql_fetchfield($query_id, $field)
{
- if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id]))
+ if ($this->sql_row_pointer[$query_id] < count($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;
}
@@ -147,7 +149,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
*/
function sql_rowseek($rownum, $query_id)
{
- if ($rownum >= sizeof($this->sql_rowset[$query_id]))
+ if ($rownum >= count($this->sql_rowset[$query_id]))
{
return false;
}
@@ -181,13 +183,9 @@ abstract class base implements \phpbb\cache\driver\driver_interface
*/
function remove_file($filename, $check = false)
{
- if (!function_exists('phpbb_is_writable'))
- {
- global $phpbb_root_path, $phpEx;
- include($phpbb_root_path . 'includes/functions.' . $phpEx);
- }
+ global $phpbb_filesystem;
- if ($check && !phpbb_is_writable($this->cache_dir))
+ if ($check && !$phpbb_filesystem->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);
diff --git a/phpBB/phpbb/cache/driver/null.php b/phpBB/phpbb/cache/driver/dummy.php
index a45cf97862..1f74f6dd77 100644
--- a/phpBB/phpbb/cache/driver/null.php
+++ b/phpBB/phpbb/cache/driver/dummy.php
@@ -14,9 +14,9 @@
namespace phpbb\cache\driver;
/**
-* ACM Null Caching
+* ACM dummy Caching
*/
-class null extends \phpbb\cache\driver\base
+class dummy extends \phpbb\cache\driver\base
{
/**
* Set cache path
@@ -52,8 +52,10 @@ class null extends \phpbb\cache\driver\base
*/
function tidy()
{
+ global $config;
+
// This cache always has a tidy room.
- set_config('cache_last_gc', time(), true);
+ $config->set('cache_last_gc', time(), false);
}
/**
diff --git a/phpBB/phpbb/cache/driver/eaccelerator.php b/phpBB/phpbb/cache/driver/eaccelerator.php
index 1697758acc..740855144f 100644
--- a/phpBB/phpbb/cache/driver/eaccelerator.php
+++ b/phpBB/phpbb/cache/driver/eaccelerator.php
@@ -44,9 +44,11 @@ class eaccelerator extends \phpbb\cache\driver\memory
*/
function tidy()
{
+ global $config;
+
eaccelerator_gc();
- set_config('cache_last_gc', time(), true);
+ $config->set('cache_last_gc', time(), false);
}
/**
diff --git a/phpBB/phpbb/cache/driver/file.php b/phpBB/phpbb/cache/driver/file.php
index 1e9ee960dc..de6f444251 100644
--- a/phpBB/phpbb/cache/driver/file.php
+++ b/phpBB/phpbb/cache/driver/file.php
@@ -21,14 +21,26 @@ class file extends \phpbb\cache\driver\base
var $var_expires = array();
/**
+ * @var \phpbb\filesystem\filesystem_interface
+ */
+ protected $filesystem;
+
+ /**
* Set cache path
*
* @param string $cache_dir Define the path to the cache directory (default: $phpbb_root_path . 'cache/')
*/
function __construct($cache_dir = null)
{
- global $phpbb_root_path;
- $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_root_path . 'cache/';
+ global $phpbb_container;
+
+ $this->cache_dir = !is_null($cache_dir) ? $cache_dir : $phpbb_container->getParameter('core.cache_dir');
+ $this->filesystem = new \phpbb\filesystem\filesystem();
+
+ if (!is_dir($this->cache_dir))
+ {
+ @mkdir($this->cache_dir, 0777, true);
+ }
}
/**
@@ -63,14 +75,8 @@ class file extends \phpbb\cache\driver\base
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))
+ if (!$this->filesystem->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('Fatal: ' . $this->cache_dir . ' is NOT writable.');
@@ -89,7 +95,7 @@ class file extends \phpbb\cache\driver\base
*/
function tidy()
{
- global $phpEx;
+ global $config, $phpEx;
$dir = @opendir($this->cache_dir);
@@ -129,7 +135,7 @@ class file extends \phpbb\cache\driver\base
if (file_exists($this->cache_dir . 'data_global.' . $phpEx))
{
- if (!sizeof($this->vars))
+ if (!count($this->vars))
{
$this->load();
}
@@ -143,7 +149,7 @@ class file extends \phpbb\cache\driver\base
}
}
- set_config('cache_last_gc', time(), true);
+ $config->set('cache_last_gc', time(), false);
}
/**
@@ -284,7 +290,7 @@ class file extends \phpbb\cache\driver\base
}
else
{
- if (!sizeof($this->vars))
+ if (!count($this->vars))
{
$this->load();
}
@@ -306,7 +312,7 @@ class file extends \phpbb\cache\driver\base
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- $query_id = sizeof($this->sql_rowset);
+ $query_id = md5($query);
$this->sql_rowset[$query_id] = array();
$this->sql_row_pointer[$query_id] = 0;
@@ -316,7 +322,7 @@ class file extends \phpbb\cache\driver\base
}
$db->sql_freeresult($query_result);
- if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query))
+ if ($this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl + time(), $query))
{
return $query_id;
}
@@ -573,13 +579,14 @@ class file extends \phpbb\cache\driver\base
@opcache_invalidate($file);
}
- if (!function_exists('phpbb_chmod'))
+ try
{
- global $phpbb_root_path;
- include($phpbb_root_path . 'includes/functions.' . $phpEx);
+ $this->filesystem->phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
+ }
+ catch (\phpbb\filesystem\exception\filesystem_exception $e)
+ {
+ // Do nothing
}
-
- phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
$return_value = true;
}
diff --git a/phpBB/phpbb/cache/driver/memcached.php b/phpBB/phpbb/cache/driver/memcached.php
index a7da22d7e8..7d66759ec2 100644
--- a/phpBB/phpbb/cache/driver/memcached.php
+++ b/phpBB/phpbb/cache/driver/memcached.php
@@ -65,10 +65,10 @@ class memcached extends \phpbb\cache\driver\memory
$this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
}
- foreach (explode(',', PHPBB_ACM_MEMCACHE) as $u)
+ foreach (explode(',', PHPBB_ACM_MEMCACHED) as $u)
{
preg_match('#(.*)/(\d+)#', $u, $parts);
- $this->memcache->addServer(trim($parts[1]), (int) trim($parts[2]));
+ $this->memcached->addServer(trim($parts[1]), (int) trim($parts[2]));
}
}
diff --git a/phpBB/phpbb/cache/driver/memory.php b/phpBB/phpbb/cache/driver/memory.php
index 0b0e323e3d..eba9549877 100644
--- a/phpBB/phpbb/cache/driver/memory.php
+++ b/phpBB/phpbb/cache/driver/memory.php
@@ -25,9 +25,9 @@ abstract class memory extends \phpbb\cache\driver\base
*/
function __construct()
{
- global $phpbb_root_path, $dbname, $table_prefix;
+ global $phpbb_root_path, $dbname, $table_prefix, $phpbb_container;
- $this->cache_dir = $phpbb_root_path . 'cache/';
+ $this->cache_dir = $phpbb_container->getParameter('core.cache_dir');
$this->key_prefix = substr(md5($dbname . $table_prefix), 0, 8) . '_';
if (!isset($this->extension) || !extension_loaded($this->extension))
@@ -51,10 +51,11 @@ abstract class memory extends \phpbb\cache\driver\base
function load()
{
// grab the global cache
- $this->vars = $this->_read('global');
+ $data = $this->_read('global');
- if ($this->vars !== false)
+ if ($data !== false)
{
+ $this->vars = $data;
return true;
}
@@ -81,9 +82,10 @@ abstract class memory extends \phpbb\cache\driver\base
*/
function tidy()
{
- // cache has auto GC, no need to have any code here :)
+ global $config;
- set_config('cache_last_gc', time(), true);
+ // cache has auto GC, no need to have any code here :)
+ $config->set('cache_last_gc', time(), false);
}
/**
@@ -187,7 +189,7 @@ abstract class memory extends \phpbb\cache\driver\base
}
else
{
- if (!sizeof($this->vars))
+ if (!count($this->vars))
{
$this->load();
}
@@ -203,7 +205,7 @@ abstract class memory extends \phpbb\cache\driver\base
{
// Remove extra spaces and tabs
$query = preg_replace('/[\n\r\s\t]+/', ' ', $query);
- $hash = md5($query);
+ $query_id = md5($query);
// determine which tables this query belongs to
// Some queries use backticks, namely the get_database_size() query
@@ -244,14 +246,13 @@ abstract class memory extends \phpbb\cache\driver\base
$temp = array();
}
- $temp[$hash] = true;
+ $temp[$query_id] = 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;
@@ -261,7 +262,7 @@ abstract class memory extends \phpbb\cache\driver\base
}
$db->sql_freeresult($query_result);
- $this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl);
+ $this->_write('sql_' . $query_id, $this->sql_rowset[$query_id], $ttl);
return $query_id;
}
diff --git a/phpBB/phpbb/cache/driver/redis.php b/phpBB/phpbb/cache/driver/redis.php
index eda774491c..eaeb529918 100644
--- a/phpBB/phpbb/cache/driver/redis.php
+++ b/phpBB/phpbb/cache/driver/redis.php
@@ -137,6 +137,10 @@ class redis extends \phpbb\cache\driver\memory
*/
function _write($var, $data, $ttl = 2592000)
{
+ if ($ttl == 0)
+ {
+ return $this->redis->set($var, $data);
+ }
return $this->redis->setex($var, $ttl, $data);
}