aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/cache
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-12-06 14:26:14 +0100
committerJoas Schilling <nickvergessen@gmx.de>2012-12-06 14:26:14 +0100
commitb4db9728400f5ec0a40bd62d992cc5a2f4832233 (patch)
treebff832f39c62157c00fde7af18006a9eb267ad30 /phpBB/includes/cache
parent98092add9e1f7fd03e347831b7d0b8db6c92939f (diff)
parent2364d4b2172c9f54520f04001b29c517d7138b69 (diff)
downloadforums-b4db9728400f5ec0a40bd62d992cc5a2f4832233.tar
forums-b4db9728400f5ec0a40bd62d992cc5a2f4832233.tar.gz
forums-b4db9728400f5ec0a40bd62d992cc5a2f4832233.tar.bz2
forums-b4db9728400f5ec0a40bd62d992cc5a2f4832233.tar.xz
forums-b4db9728400f5ec0a40bd62d992cc5a2f4832233.zip
Merge branch 'develop' of https://github.com/phpbb/phpbb3 into ticket/10411-2
* 'develop' of https://github.com/phpbb/phpbb3: (204 commits) [ticket/11219] Coding guidelines and naming consistency changes [ticket/10841] Revert more whitespace changes. [ticket/10841] Revert whitespace changes. [ticket/10841] adding space after if [ticket/10841] removing unnecessary spacing [ticket/10841] changing affectedrows check to COUNT in sql [ticket/10841] Modifying style and language selectors in UCP [ticket/11247] Fix wrong property reference in flock class. [ticket/10602] Avoid a race condition. [ticket/10602] Use last_queue_run for its intended purpose. [ticket/10716] Collect standard error from executed php process. [ticket/10716] Skip test if php is not in PATH. [ticket/10716] Exclude our dependencies from linting. [ticket/10103] New and improved wording. [ticket/10716] Only lint on php 5.3+. [ticket/10103] Assert with messages. [ticket/10103] assertLessThan/assertGreaterThan. [ticket/10103] Inline assignment is bad? [ticket/10103] $rv had too few characters. [ticket/10103] Correct flock class documentation. ... Conflicts: phpBB/config/services.yml phpBB/includes/groupposition/legend.php
Diffstat (limited to 'phpBB/includes/cache')
-rw-r--r--phpBB/includes/cache/driver/apc.php2
-rw-r--r--phpBB/includes/cache/driver/eaccelerator.php4
-rw-r--r--phpBB/includes/cache/driver/file.php21
-rw-r--r--phpBB/includes/cache/driver/interface.php47
-rw-r--r--phpBB/includes/cache/driver/memcache.php4
-rw-r--r--phpBB/includes/cache/driver/memory.php5
-rw-r--r--phpBB/includes/cache/driver/null.php1
-rw-r--r--phpBB/includes/cache/driver/redis.php32
-rw-r--r--phpBB/includes/cache/driver/wincache.php2
-rw-r--r--phpBB/includes/cache/driver/xcache.php2
10 files changed, 96 insertions, 24 deletions
diff --git a/phpBB/includes/cache/driver/apc.php b/phpBB/includes/cache/driver/apc.php
index dc0144fac3..0516b669c8 100644
--- a/phpBB/includes/cache/driver/apc.php
+++ b/phpBB/includes/cache/driver/apc.php
@@ -26,7 +26,7 @@ class phpbb_cache_driver_apc extends phpbb_cache_driver_memory
/**
* Purge cache data
*
- * @return void
+ * @return null
*/
function purge()
{
diff --git a/phpBB/includes/cache/driver/eaccelerator.php b/phpBB/includes/cache/driver/eaccelerator.php
index 7939f043c9..257b90c76e 100644
--- a/phpBB/includes/cache/driver/eaccelerator.php
+++ b/phpBB/includes/cache/driver/eaccelerator.php
@@ -30,7 +30,7 @@ class phpbb_cache_driver_eaccelerator extends phpbb_cache_driver_memory
/**
* Purge cache data
*
- * @return void
+ * @return null
*/
function purge()
{
@@ -47,7 +47,7 @@ class phpbb_cache_driver_eaccelerator extends phpbb_cache_driver_memory
/**
* Perform cache garbage collection
*
- * @return void
+ * @return null
*/
function tidy()
{
diff --git a/phpBB/includes/cache/driver/file.php b/phpBB/includes/cache/driver/file.php
index 32bdb1918a..691abe0438 100644
--- a/phpBB/includes/cache/driver/file.php
+++ b/phpBB/includes/cache/driver/file.php
@@ -215,6 +215,7 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
while (($entry = readdir($dir)) !== false)
{
if (strpos($entry, 'container_') !== 0 &&
+ strpos($entry, 'url_matcher') !== 0 &&
strpos($entry, 'sql_') !== 0 &&
strpos($entry, 'data_') !== 0 &&
strpos($entry, 'ctpl_') !== 0 &&
@@ -387,10 +388,10 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
if ($this->_write('sql_' . md5($query), $this->sql_rowset[$query_id], $ttl + time(), $query))
{
- $query_result = $query_id;
+ return $query_id;
}
- return $query_id;
+ return $query_result;
}
/**
@@ -652,10 +653,11 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
$file = "{$this->cache_dir}$filename.$phpEx";
+ $lock = new phpbb_lock_flock($file);
+ $lock->acquire();
+
if ($handle = @fopen($file, 'wb'))
{
- @flock($handle, LOCK_EX);
-
// File header
fwrite($handle, '<' . '?php exit; ?' . '>');
@@ -696,7 +698,6 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
fwrite($handle, $data);
}
- @flock($handle, LOCK_UN);
fclose($handle);
if (!function_exists('phpbb_chmod'))
@@ -707,10 +708,16 @@ class phpbb_cache_driver_file extends phpbb_cache_driver_base
phpbb_chmod($file, CHMOD_READ | CHMOD_WRITE);
- return true;
+ $return_value = true;
+ }
+ else
+ {
+ $return_value = false;
}
- return false;
+ $lock->release();
+
+ return $return_value;
}
/**
diff --git a/phpBB/includes/cache/driver/interface.php b/phpBB/includes/cache/driver/interface.php
index 847ba97262..d403bbcd71 100644
--- a/phpBB/includes/cache/driver/interface.php
+++ b/phpBB/includes/cache/driver/interface.php
@@ -63,42 +63,81 @@ interface phpbb_cache_driver_interface
public function destroy($var_name, $table = '');
/**
- * Check if a given cache entry exist
+ * Check if a given cache entry exists
*/
public function _exists($var_name);
/**
- * Load cached sql query
+ * Load result of an SQL query from cache.
+ *
+ * @param string $query SQL query
+ *
+ * @return int|bool Query ID (integer) if cache contains a rowset
+ * for the specified query.
+ * False otherwise.
*/
public function sql_load($query);
/**
- * Save sql query
+ * Save result of an SQL query in cache.
+ *
+ * In persistent cache stores, this function stores the query
+ * result to persistent storage. In other words, there is no need
+ * to call save() afterwards.
+ *
+ * @param string $query SQL query, should be used for generating storage key
+ * @param mixed $query_result The result from dbal::sql_query, to be passed to
+ * dbal::sql_fetchrow to get all rows and store them
+ * in cache.
+ * @param int $ttl Time to live, after this timeout the query should
+ * expire from the cache.
+ * @return int|mixed If storing in cache succeeded, an integer $query_id
+ * representing the query should be returned. Otherwise
+ * the original $query_result should be returned.
*/
public function sql_save($query, $query_result, $ttl);
/**
- * Ceck if a given sql query exist in cache
+ * Check if result for a given SQL query exists in cache.
+ *
+ * @param int $query_id
+ * @return bool
*/
public function sql_exists($query_id);
/**
* Fetch row from cache (database)
+ *
+ * @param int $query_id
+ * @return array|bool The query result if found in the cache, otherwise
+ * false.
*/
public function sql_fetchrow($query_id);
/**
* Fetch a field from the current row of a cached database result (database)
+ *
+ * @param int $query_id
+ * @param $field The name of the column.
+ * @return string|bool The field of the query result if found in the cache,
+ * otherwise false.
*/
public function sql_fetchfield($query_id, $field);
/**
* Seek a specific row in an a cached database result (database)
+ *
+ * @param int $rownum Row to seek to.
+ * @param int $query_id
+ * @return bool
*/
public function sql_rowseek($rownum, $query_id);
/**
* Free memory used for a cached database result (database)
+ *
+ * @param int $query_id
+ * @return bool
*/
public function sql_freeresult($query_id);
}
diff --git a/phpBB/includes/cache/driver/memcache.php b/phpBB/includes/cache/driver/memcache.php
index 9fe70f8b44..3fd16b23b0 100644
--- a/phpBB/includes/cache/driver/memcache.php
+++ b/phpBB/includes/cache/driver/memcache.php
@@ -64,7 +64,7 @@ class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory
/**
* Unload the cache resources
*
- * @return void
+ * @return null
*/
function unload()
{
@@ -76,7 +76,7 @@ class phpbb_cache_driver_memcache extends phpbb_cache_driver_memory
/**
* Purge cache data
*
- * @return void
+ * @return null
*/
function purge()
{
diff --git a/phpBB/includes/cache/driver/memory.php b/phpBB/includes/cache/driver/memory.php
index 1ea9a3e9e7..c39f9f7850 100644
--- a/phpBB/includes/cache/driver/memory.php
+++ b/phpBB/includes/cache/driver/memory.php
@@ -163,6 +163,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
while (($entry = readdir($dir)) !== false)
{
if (strpos($entry, 'container_') !== 0 &&
+ strpos($entry, 'url_matcher') !== 0 &&
strpos($entry, 'sql_') !== 0 &&
strpos($entry, 'data_') !== 0 &&
strpos($entry, 'ctpl_') !== 0 &&
@@ -298,7 +299,7 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
if (!preg_match('/FROM \\(?(`?\\w+`?(?: \\w+)?(?:, ?`?\\w+`?(?: \\w+)?)*)\\)?/', $query, $regs))
{
// Bail out if the match fails.
- return;
+ return $query_result;
}
$tables = array_map('trim', explode(',', $regs[1]));
@@ -338,8 +339,6 @@ abstract class phpbb_cache_driver_memory extends phpbb_cache_driver_base
$this->_write('sql_' . $hash, $this->sql_rowset[$query_id], $ttl);
- $query_result = $query_id;
-
return $query_id;
}
diff --git a/phpBB/includes/cache/driver/null.php b/phpBB/includes/cache/driver/null.php
index df2c6c026f..687604d14f 100644
--- a/phpBB/includes/cache/driver/null.php
+++ b/phpBB/includes/cache/driver/null.php
@@ -109,6 +109,7 @@ class phpbb_cache_driver_null extends phpbb_cache_driver_base
*/
function sql_save($query, $query_result, $ttl)
{
+ return $query_result;
}
/**
diff --git a/phpBB/includes/cache/driver/redis.php b/phpBB/includes/cache/driver/redis.php
index a768885962..960735b673 100644
--- a/phpBB/includes/cache/driver/redis.php
+++ b/phpBB/includes/cache/driver/redis.php
@@ -39,13 +39,39 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory
var $redis;
+ /**
+ * Creates a redis cache driver.
+ *
+ * The following global constants affect operation:
+ *
+ * PHPBB_ACM_REDIS_HOST
+ * PHPBB_ACM_REDIS_PORT
+ * PHPBB_ACM_REDIS_PASSWORD
+ * PHPBB_ACM_REDIS_DB
+ *
+ * There are no publicly documented constructor parameters.
+ */
function __construct()
{
// Call the parent constructor
parent::__construct();
$this->redis = new Redis();
- $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
+
+ $args = func_get_args();
+ if (!empty($args))
+ {
+ $ok = call_user_func_array(array($this->redis, 'connect'), $args);
+ }
+ else
+ {
+ $ok = $this->redis->connect(PHPBB_ACM_REDIS_HOST, PHPBB_ACM_REDIS_PORT);
+ }
+
+ if (!$ok)
+ {
+ trigger_error('Could not connect to redis server');
+ }
if (defined('PHPBB_ACM_REDIS_PASSWORD'))
{
@@ -74,7 +100,7 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory
/**
* Unload the cache resources
*
- * @return void
+ * @return null
*/
function unload()
{
@@ -86,7 +112,7 @@ class phpbb_cache_driver_redis extends phpbb_cache_driver_memory
/**
* Purge cache data
*
- * @return void
+ * @return null
*/
function purge()
{
diff --git a/phpBB/includes/cache/driver/wincache.php b/phpBB/includes/cache/driver/wincache.php
index fa9eb95f88..58f3b4a581 100644
--- a/phpBB/includes/cache/driver/wincache.php
+++ b/phpBB/includes/cache/driver/wincache.php
@@ -26,7 +26,7 @@ class phpbb_cache_driver_wincache extends phpbb_cache_driver_memory
/**
* Purge cache data
*
- * @return void
+ * @return null
*/
function purge()
{
diff --git a/phpBB/includes/cache/driver/xcache.php b/phpBB/includes/cache/driver/xcache.php
index 0b768bdb3e..06c5fafd97 100644
--- a/phpBB/includes/cache/driver/xcache.php
+++ b/phpBB/includes/cache/driver/xcache.php
@@ -41,7 +41,7 @@ class phpbb_cache_driver_xcache extends phpbb_cache_driver_memory
/**
* Purge cache data
*
- * @return void
+ * @return null
*/
function purge()
{