Upgrade to 3.1.3
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Kirby\Cache;
|
||||
|
||||
use APCUIterator;
|
||||
|
||||
/**
|
||||
* APCu Cache Driver
|
||||
*
|
||||
@@ -14,6 +16,53 @@ namespace Kirby\Cache;
|
||||
class ApcuCache extends Cache
|
||||
{
|
||||
|
||||
/**
|
||||
* Checks if the current key exists in cache
|
||||
*
|
||||
* @param string $key
|
||||
* @return boolean
|
||||
*/
|
||||
public function exists(string $key): bool
|
||||
{
|
||||
return apcu_exists($this->key($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the entire cache directory
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function flush(): bool
|
||||
{
|
||||
if (empty($this->options['prefix']) === false) {
|
||||
return apcu_delete(new APCUIterator('!^' . preg_quote($this->options['prefix']) . '!'));
|
||||
} else {
|
||||
return apcu_clear_cache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @param string $key
|
||||
* @return boolean
|
||||
*/
|
||||
public function remove(string $key): bool
|
||||
{
|
||||
return apcu_delete($this->key($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function retrieve(string $key)
|
||||
{
|
||||
return Value::fromJson(apcu_fetch($this->key($key)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an item to the cache for a given number of minutes.
|
||||
*
|
||||
@@ -29,49 +78,6 @@ class ApcuCache extends Cache
|
||||
*/
|
||||
public function set(string $key, $value, int $minutes = 0)
|
||||
{
|
||||
return apcu_store($key, $this->value($value, $minutes)->toJson(), $this->expiration($minutes));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an item from the cache.
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function retrieve(string $key)
|
||||
{
|
||||
return Value::fromJson(apcu_fetch($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current key exists in cache
|
||||
*
|
||||
* @param string $key
|
||||
* @return boolean
|
||||
*/
|
||||
public function exists(string $key): bool
|
||||
{
|
||||
return apcu_exists($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an item from the cache
|
||||
*
|
||||
* @param string $key
|
||||
* @return boolean
|
||||
*/
|
||||
public function remove(string $key): bool
|
||||
{
|
||||
return apcu_delete($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the entire cache directory
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function flush(): bool
|
||||
{
|
||||
return apcu_clear_cache();
|
||||
return apcu_store($this->key($key), $this->value($value, $minutes)->toJson(), $this->expiration($minutes));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,21 @@ class Cache
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the prefix to the key if given
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function key(string $key): string
|
||||
{
|
||||
if (empty($this->options['prefix']) === false) {
|
||||
$key = $this->options['prefix'] . '/' . $key;
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private method to retrieve the cache value
|
||||
* This needs to be defined by the driver
|
||||
|
||||
@@ -35,11 +35,6 @@ class FileCache extends Cache
|
||||
|
||||
// try to create the directory
|
||||
Dir::make($this->options['root'], true);
|
||||
|
||||
// check for a valid cache directory
|
||||
if (is_dir($this->options['root']) === false) {
|
||||
throw new Exception('The cache directory does not exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +46,8 @@ class FileCache extends Cache
|
||||
protected function file(string $key): string
|
||||
{
|
||||
$extension = isset($this->options['extension']) ? '.' . $this->options['extension'] : '';
|
||||
return $this->options['root'] . '/' . $key . $extension;
|
||||
|
||||
return $this->options['root'] . '/' . $this->key($key) . $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +113,13 @@ class FileCache extends Cache
|
||||
*/
|
||||
public function flush(): bool
|
||||
{
|
||||
if (Dir::remove($this->options['root']) === true && Dir::make($this->options['root']) === true) {
|
||||
$root = $this->options['root'];
|
||||
|
||||
if (empty($this->options['prefix']) === false) {
|
||||
$root = $root . '/' . $this->options['prefix'];
|
||||
}
|
||||
|
||||
if (Dir::remove($root) === true && Dir::make($root) === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user