From 85eaf308d5a7cc00eb4ea78a9a683f4e42cfb5c0 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Sat, 19 Feb 2022 13:17:19 +0200 Subject: [PATCH] Fixed FlexDirectory::getCache() after converting to Symfony Cache --- system/src/Grav/Common/Cache.php | 15 ++++++++++----- system/src/Grav/Framework/Flex/FlexDirectory.php | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index e99f95712..0032fdcb7 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -11,6 +11,7 @@ namespace Grav\Common; use DirectoryIterator; use Doctrine\Common\Cache\Cache as DoctrineCache; +use Doctrine\Common\Cache\CacheProvider; use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Exception; use Grav\Common\Config\Config; @@ -58,7 +59,7 @@ class Cache extends Getters /** @var AdapterInterface */ protected $adapter; - /** @var DoctrineCache */ + /** @var CacheProvider */ protected $driver; /** @var CacheInterface */ @@ -235,9 +236,13 @@ class Cache extends Getters * If there is no config option for $driver in the config, or it's set to 'auto', it will * pick the best option based on which cache extensions are installed. * + * @param string|null $namespace + * @param int|null $defaultLifetime * @return AdapterInterface The cache driver to use + * @throws \RedisException + * @throws \Symfony\Component\Cache\Exception\CacheException */ - public function getCacheAdapter(): AdapterInterface + public function getCacheAdapter(string $namespace = null, int $defaultLifetime = null): AdapterInterface { $setting = $this->driver_setting ?? 'auto'; $driver_name = 'file'; @@ -260,13 +265,13 @@ class Cache extends Getters } $this->driver_name = $driver_name; - $namespace = $this->key; - $defaultLifetime = 0; + $namespace = $namespace ?? $this->key; + $defaultLifetime = $defaultLifetime ?? 0; switch ($driver_name) { case 'apc': case 'apcu': - $adapter = new ApcuAdapter($namespace, $defaultLifetime); + $adapter = new ApcuAdapter($namespace, $defaultLifetime); break; case 'memcached': diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index f96633b31..472a5ffa8 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -34,6 +34,7 @@ use Psr\SimpleCache\InvalidArgumentException; use RocketTheme\Toolbox\File\YamlFile; use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator; use RuntimeException; +use Symfony\Component\Cache\Psr16Cache; use function call_user_func_array; use function count; use function is_array; @@ -421,7 +422,8 @@ class FlexDirectory implements FlexDirectoryInterface if (Utils::isAdminPlugin()) { $key = substr($key, 0, -1); } - $cache = new DoctrineCache($gravCache->getCacheDriver(), 'flex-objects-' . $this->getFlexType() . $key, $lifetime); + + $cache = new Psr16Cache($gravCache->getCacheAdapter('flex-objects-' . $this->getFlexType() . $key, $lifetime)); } } catch (Exception $e) { /** @var Debugger $debugger */