update kirby to v5 and add refresh cache panel view button
This commit is contained in:
commit
9a86d41254
466 changed files with 19960 additions and 10497 deletions
|
|
@ -68,10 +68,10 @@ class ApcuCache extends Cache
|
|||
* Writes an item to the cache for a given number of minutes and
|
||||
* returns whether the operation was successful
|
||||
*
|
||||
* <code>
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* </code>
|
||||
* ```php
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* ```
|
||||
*/
|
||||
public function set(string $key, $value, int $minutes = 0): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ abstract class Cache
|
|||
return $this->expired($key) === false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calculates the expiration timestamp
|
||||
*/
|
||||
|
|
@ -132,13 +131,13 @@ abstract class Cache
|
|||
/**
|
||||
* Gets an item from the cache
|
||||
*
|
||||
* <code>
|
||||
* // get an item from the cache driver
|
||||
* $value = $cache->get('value');
|
||||
* ```php
|
||||
* // get an item from the cache driver
|
||||
* $value = $cache->get('value');
|
||||
*
|
||||
* // return a default value if the requested item isn't cached
|
||||
* $value = $cache->get('value', 'default value');
|
||||
* </code>
|
||||
* // return a default value if the requested item isn't cached
|
||||
* $value = $cache->get('value', 'default value');
|
||||
* ```
|
||||
*/
|
||||
public function get(string $key, $default = null)
|
||||
{
|
||||
|
|
@ -229,10 +228,10 @@ abstract class Cache
|
|||
* returns whether the operation was successful;
|
||||
* this needs to be defined by the driver
|
||||
*
|
||||
* <code>
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* </code>
|
||||
* ```php
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* ```
|
||||
*/
|
||||
abstract public function set(string $key, $value, int $minutes = 0): bool;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,13 +32,12 @@ class FileCache extends Cache
|
|||
*/
|
||||
public function __construct(array $options)
|
||||
{
|
||||
$defaults = [
|
||||
parent::__construct([
|
||||
'root' => null,
|
||||
'prefix' => null,
|
||||
'extension' => null
|
||||
];
|
||||
|
||||
parent::__construct(array_merge($defaults, $options));
|
||||
'extension' => null,
|
||||
...$options
|
||||
]);
|
||||
|
||||
// build the full root including prefix
|
||||
$this->root = $this->options['root'];
|
||||
|
|
@ -120,10 +119,10 @@ class FileCache extends Cache
|
|||
* Writes an item to the cache for a given number of minutes and
|
||||
* returns whether the operation was successful
|
||||
*
|
||||
* <code>
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* </code>
|
||||
* ```php
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* ```
|
||||
*/
|
||||
public function set(string $key, $value, int $minutes = 0): bool
|
||||
{
|
||||
|
|
@ -196,7 +195,7 @@ class FileCache extends Cache
|
|||
|
||||
$files = array_diff($files, ['.', '..']);
|
||||
|
||||
if (empty($files) === true && Dir::remove($dir) === true) {
|
||||
if ($files === [] && Dir::remove($dir) === true) {
|
||||
// continue with the next level up
|
||||
$dir = dirname($dir);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -34,13 +34,12 @@ class MemCached extends Cache
|
|||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$defaults = [
|
||||
parent::__construct([
|
||||
'host' => 'localhost',
|
||||
'port' => 11211,
|
||||
'prefix' => null,
|
||||
];
|
||||
|
||||
parent::__construct(array_merge($defaults, $options));
|
||||
...$options
|
||||
]);
|
||||
|
||||
$this->connection = new MemcachedExt();
|
||||
$this->enabled = $this->connection->addServer(
|
||||
|
|
@ -62,10 +61,10 @@ class MemCached extends Cache
|
|||
* Writes an item to the cache for a given number of minutes and
|
||||
* returns whether the operation was successful
|
||||
*
|
||||
* <code>
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* </code>
|
||||
* ```php
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* ```
|
||||
*/
|
||||
public function set(string $key, $value, int $minutes = 0): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ class MemoryCache extends Cache
|
|||
* Writes an item to the cache for a given number of minutes and
|
||||
* returns whether the operation was successful
|
||||
*
|
||||
* <code>
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* </code>
|
||||
* ```php
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* ```
|
||||
*/
|
||||
public function set(string $key, $value, int $minutes = 0): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ class NullCache extends Cache
|
|||
* Writes an item to the cache for a given number of minutes and
|
||||
* returns whether the operation was successful
|
||||
*
|
||||
* <code>
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* </code>
|
||||
* ```php
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* ```
|
||||
*/
|
||||
public function set(string $key, $value, int $minutes = 0): bool
|
||||
{
|
||||
|
|
|
|||
160
public/kirby/src/Cache/RedisCache.php
Normal file
160
public/kirby/src/Cache/RedisCache.php
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Cache;
|
||||
|
||||
use Kirby\Cms\Helpers;
|
||||
use Redis;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Redis Cache Driver
|
||||
*
|
||||
* @package Kirby Cache
|
||||
* @author Ahmet Bora <ahmet@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
class RedisCache extends Cache
|
||||
{
|
||||
/**
|
||||
* Store for the redis connection
|
||||
*/
|
||||
protected Redis $connection;
|
||||
|
||||
/**
|
||||
* Sets all parameters which are needed to connect to Redis
|
||||
*
|
||||
* @param array $options 'host' (default: 127.0.0.1)
|
||||
* 'port' (default: 6379)
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$options = [
|
||||
'host' => '127.0.0.1',
|
||||
'port' => 6379,
|
||||
...$options
|
||||
];
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
// available options for the redis driver
|
||||
$allowed = [
|
||||
'host',
|
||||
'port',
|
||||
'readTimeout',
|
||||
'connectTimeout',
|
||||
'persistent',
|
||||
'auth',
|
||||
'ssl',
|
||||
'retryInterval',
|
||||
'backoff'
|
||||
];
|
||||
|
||||
// filters only redis supported keys
|
||||
$redisOptions = array_intersect_key($options, array_flip($allowed));
|
||||
|
||||
// creates redis connection
|
||||
$this->connection = new Redis($redisOptions);
|
||||
|
||||
// sets the prefix if defined
|
||||
if ($prefix = $options['prefix'] ?? null) {
|
||||
$this->connection->setOption(Redis::OPT_PREFIX, rtrim($prefix, '/') . '/');
|
||||
}
|
||||
|
||||
// selects the database if defined
|
||||
$database = $options['database'] ?? null;
|
||||
if ($database !== null) {
|
||||
$this->connection->select($database);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the database number
|
||||
*/
|
||||
public function databaseNum(): int
|
||||
{
|
||||
return $this->connection->getDbNum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the cache is ready to store values
|
||||
*/
|
||||
public function enabled(): bool
|
||||
{
|
||||
try {
|
||||
return Helpers::handleErrors(
|
||||
fn () => $this->connection->ping(),
|
||||
fn (int $errno, string $errstr) => true,
|
||||
fn () => false
|
||||
);
|
||||
} catch (Throwable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an item exists in the cache
|
||||
*/
|
||||
public function exists(string $key): bool
|
||||
{
|
||||
return $this->connection->exists($this->key($key)) !== 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes keys from the database
|
||||
* and returns whether the operation was successful
|
||||
*/
|
||||
public function flush(): bool
|
||||
{
|
||||
return $this->connection->flushDB();
|
||||
}
|
||||
|
||||
/**
|
||||
* The key is not modified, because the prefix is added by the redis driver itself
|
||||
*/
|
||||
protected function key(string $key): string
|
||||
{
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an item from the cache
|
||||
* and returns whether the operation was successful
|
||||
*/
|
||||
public function remove(string $key): bool
|
||||
{
|
||||
return $this->connection->del($this->key($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method to retrieve the raw cache value;
|
||||
* needs to return a Value object or null if not found
|
||||
*/
|
||||
public function retrieve(string $key): Value|null
|
||||
{
|
||||
$value = $this->connection->get($this->key($key));
|
||||
return Value::fromJson($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an item to the cache for a given number of minutes
|
||||
* and returns whether the operation was successful
|
||||
*
|
||||
* ```php
|
||||
* // put an item in the cache for 15 minutes
|
||||
* $cache->set('value', 'my value', 15);
|
||||
* ```
|
||||
*/
|
||||
public function set(string $key, $value, int $minutes = 0): bool
|
||||
{
|
||||
$key = $this->key($key);
|
||||
$value = (new Value($value, $minutes))->toJson();
|
||||
|
||||
if ($minutes > 0) {
|
||||
return $this->connection->setex($key, $minutes * 60, $value);
|
||||
}
|
||||
|
||||
return $this->connection->set($key, $value);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ class Value
|
|||
/**
|
||||
* Cached value
|
||||
*/
|
||||
protected $value;
|
||||
protected mixed $value;
|
||||
|
||||
/**
|
||||
* the number of minutes until the value expires
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue