1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-04 15:57:45 +02:00

[ticket/16955] Add stubs for cache classes and clean up

PHPBB3-16955
This commit is contained in:
Marc Alexander
2022-12-27 16:12:53 +01:00
parent b855b8a5a5
commit 83cb41e72a
15 changed files with 153 additions and 119 deletions

View File

@@ -38,39 +38,25 @@ class apcu extends \phpbb\cache\driver\memory
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
* {@inheritDoc}
*/
function _read($var)
protected function _read(string $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
* {@inheritDoc}
*/
function _write($var, $data, $ttl = 2592000)
protected function _write(string $var, $data, int $ttl = 2592000): bool
{
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)
* {@inheritDoc}
*/
protected function _delete(string $var): bool
{
return apcu_delete($this->key_prefix . $var);
}

View File

@@ -199,7 +199,7 @@ abstract class base implements \phpbb\cache\driver\driver_interface
*
* @param string $dir Directory to remove
*
* @return null
* @return void
*/
protected function remove_dir($dir)
{
@@ -231,4 +231,13 @@ abstract class base implements \phpbb\cache\driver\driver_interface
@rmdir($dir);
}
/**
* Fetch an item from the cache
*
* @param string $var Cache key
*
* @return mixed Cached data
*/
abstract protected function _read(string $var);
}

View File

@@ -95,7 +95,7 @@ interface driver_interface
*
* @param string $query SQL query
*
* @return int|bool Query ID (integer) if cache contains a rowset
* @return string|false Query ID (md5 of query) if cache contains a rowset
* for the specified query.
* False otherwise.
*/

View File

@@ -95,6 +95,14 @@ class dummy extends \phpbb\cache\driver\base
return false;
}
/**
* {@inheritDoc}
*/
protected function _read(string $var)
{
return false;
}
/**
* {@inheritDoc}
*/

View File

@@ -331,17 +331,13 @@ class file extends \phpbb\cache\driver\base
}
/**
* 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)
* {@inheritDoc}
*/
protected function _read(string $var)
{
global $phpEx;
$filename = $this->clean_varname($filename);
$filename = $this->clean_varname($var);
$file = "{$this->cache_dir}$filename.$phpEx";
$type = substr($filename, 0, strpos($filename, '_'));

View File

@@ -37,7 +37,7 @@ if (!defined('PHPBB_ACM_MEMCACHED'))
/**
* ACM for Memcached
*/
class memcached extends \phpbb\cache\driver\memory
class memcached extends memory
{
/** @var string Extension to use */
protected $extension = 'memcached';
@@ -107,26 +107,17 @@ class memcached extends \phpbb\cache\driver\memory
}
/**
* Fetch an item from the cache
*
* @param string $var Cache key
*
* @return mixed Cached data
*/
protected function _read($var)
* {@inheritDoc}
*/
protected function _read(string $var)
{
return $this->memcached->get($this->key_prefix . $var);
}
/**
* Store data in the cache
*
* @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
* {@inheritDoc}
*/
protected function _write($var, $data, $ttl = 2592000)
protected function _write(string $var, $data, int $ttl = 2592000): bool
{
if (!$this->memcached->replace($this->key_prefix . $var, $data, $ttl))
{
@@ -136,12 +127,9 @@ class memcached extends \phpbb\cache\driver\memory
}
/**
* Remove an item from the cache
*
* @param string $var Cache key
* @return bool True if the operation succeeded
* {@inheritDoc}
*/
protected function _delete($var)
protected function _delete(string $var): bool
{
return $this->memcached->delete($this->key_prefix . $var);
}

View File

@@ -270,13 +270,33 @@ abstract class memory extends \phpbb\cache\driver\base
/**
* Check if a cache var exists
*
* @access protected
* @param string $var Cache key
*
* @return bool True if it exists, otherwise false
*/
function _isset($var)
protected function _isset(string $var): bool
{
// Most caches don't need to check
return true;
}
/**
* Remove an item from the cache
*
* @param string $var Cache key
*
* @return bool True if the operation succeeded
*/
abstract protected function _delete(string $var): bool;
/**
* Store data in the cache
*
* @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
*/
abstract protected function _write(string $var, $data, int $ttl = 2592000): bool;
}

View File

@@ -115,27 +115,17 @@ class redis extends \phpbb\cache\driver\memory
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
* {@inheritDoc}
*/
protected function _read(string $var)
{
return $this->redis->get($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
* {@inheritDoc}
*/
function _write($var, $data, $ttl = 2592000)
protected function _write(string $var, $data, int $ttl = 2592000): bool
{
if ($ttl == 0)
{
@@ -145,13 +135,9 @@ class redis extends \phpbb\cache\driver\memory
}
/**
* Remove an item from the cache
*
* @access protected
* @param string $var Cache key
* @return bool True if the operation succeeded
*/
function _delete($var)
* {@inheritDoc}
*/
protected function _delete(string $var): bool
{
if ($this->redis->delete($var) > 0)
{

View File

@@ -31,13 +31,9 @@ class wincache extends \phpbb\cache\driver\memory
}
/**
* Fetch an item from the cache
*
* @access protected
* @param string $var Cache key
* @return mixed Cached data
*/
function _read($var)
* {@inheritDoc}
*/
protected function _read(string $var)
{
$success = false;
$result = wincache_ucache_get($this->key_prefix . $var, $success);
@@ -46,27 +42,17 @@ class wincache extends \phpbb\cache\driver\memory
}
/**
* 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
* {@inheritDoc}
*/
function _write($var, $data, $ttl = 2592000)
protected function _write(string $var, $data, int $ttl = 2592000): bool
{
return wincache_ucache_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)
* {@inheritDoc}
*/
protected function _delete(string $var): bool
{
return wincache_ucache_delete($this->key_prefix . $var);
}