diff --git a/src/Cache/Recording/Factory.php b/src/Cache/Recording/Factory.php index a59385a..e19ff73 100644 --- a/src/Cache/Recording/Factory.php +++ b/src/Cache/Recording/Factory.php @@ -12,6 +12,7 @@ namespace Cache\CacheBundle\Cache\Recording; use Cache\Hierarchy\HierarchicalPoolInterface; +use Cache\TagInterop\TaggableCacheItemPoolInterface; use Psr\Cache\CacheItemPoolInterface; use Psr\Log\LoggerInterface; diff --git a/src/DependencyInjection/CacheExtension.php b/src/DependencyInjection/CacheExtension.php index 7840578..72f9b21 100644 --- a/src/DependencyInjection/CacheExtension.php +++ b/src/DependencyInjection/CacheExtension.php @@ -14,6 +14,7 @@ use Cache\Bridge\Doctrine\DoctrineCacheBridge; use Cache\CacheBundle\Bridge\SymfonyValidatorBridge; use Cache\CacheBundle\Factory\DoctrineBridgeFactory; +use Cache\CacheBundle\Factory\RouterFactory; use Cache\CacheBundle\Factory\SessionHandlerFactory; use Cache\CacheBundle\Factory\ValidationFactory; use Cache\CacheBundle\Routing\CachingRouter; @@ -152,6 +153,7 @@ private function registerServices(ContainerBuilder $container, $config) if ($config['router']['enabled']) { $container->register('cache.service.router', CachingRouter::class) + ->setFactory([RouterFactory::class, 'get']) ->setDecoratedService('router', null, 10) ->addArgument(new Reference($config['router']['service_id'])) ->addArgument(new Reference('cache.service.router.inner')) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 85de2a4..9d35f6f 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -84,6 +84,7 @@ private function addSerializerSection() ->children() ->scalarNode('service_id')->isRequired()->end() ->booleanNode('use_tagging')->defaultTrue()->end() + ->scalarNode('prefix')->defaultValue('')->end() ->end(); return $node; @@ -105,6 +106,7 @@ private function addValidationSection() ->children() ->scalarNode('service_id')->isRequired()->end() ->booleanNode('use_tagging')->defaultTrue()->end() + ->scalarNode('prefix')->defaultValue('')->end() ->end(); return $node; @@ -126,6 +128,7 @@ private function addAnnotationSection() ->children() ->scalarNode('service_id')->isRequired()->end() ->booleanNode('use_tagging')->defaultTrue()->end() + ->scalarNode('prefix')->defaultValue('')->end() ->end(); return $node; @@ -227,6 +230,8 @@ private function addRouterSection() ->scalarNode('service_id') ->isRequired() ->end() + ->booleanNode('use_tagging')->defaultTrue()->end() + ->scalarNode('prefix')->defaultValue('')->end() ->end(); return $node; diff --git a/src/Factory/DoctrineBridgeFactory.php b/src/Factory/DoctrineBridgeFactory.php index abe35f8..a1982a5 100644 --- a/src/Factory/DoctrineBridgeFactory.php +++ b/src/Factory/DoctrineBridgeFactory.php @@ -13,6 +13,7 @@ use Cache\Bridge\Doctrine\DoctrineCacheBridge; use Cache\CacheBundle\Cache\FixedTaggingCachePool; +use Cache\Prefixed\PrefixedCachePool; use Cache\Taggable\TaggablePSR6PoolAdapter; use Psr\Cache\CacheItemPoolInterface; @@ -28,12 +29,16 @@ class DoctrineBridgeFactory * * @return DoctrineCacheBridge */ - public static function get(CacheItemPoolInterface $pool, $config, array $tags) + public static function get(CacheItemPoolInterface $pool, array $config, array $tags) { if ($config['use_tagging']) { $pool = new FixedTaggingCachePool(TaggablePSR6PoolAdapter::makeTaggable($pool), $tags); } + if (!empty($config['prefix'])) { + $pool = new PrefixedCachePool($pool, $config['prefix']); + } + return new DoctrineCacheBridge($pool); } } diff --git a/src/Factory/RouterFactory.php b/src/Factory/RouterFactory.php new file mode 100644 index 0000000..c5cab3d --- /dev/null +++ b/src/Factory/RouterFactory.php @@ -0,0 +1,44 @@ +, Tobias Nyholm + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace Cache\CacheBundle\Factory; + +use Cache\CacheBundle\Routing\CachingRouter; +use Cache\Prefixed\PrefixedCachePool; +use Cache\Taggable\TaggablePSR6PoolAdapter; +use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\Routing\RouterInterface; + +/** + * @author Tobias Nyholm + */ +class RouterFactory +{ + /** + * @param CacheItemPoolInterface $pool + * @param RouterInterface $router + * @param array $config + * + * @return CachingRouter + */ + public static function get(CacheItemPoolInterface $pool, RouterInterface $router, array $config) + { + if ($config['use_tagging']) { + $pool = TaggablePSR6PoolAdapter::makeTaggable($pool); + } + + if (!empty($config['prefix'])) { + $pool = new PrefixedCachePool($pool, $config['prefix']); + } + + return new CachingRouter($pool, $router, $config); + } +} diff --git a/src/Factory/SessionHandlerFactory.php b/src/Factory/SessionHandlerFactory.php index de6a31a..1fd31a2 100644 --- a/src/Factory/SessionHandlerFactory.php +++ b/src/Factory/SessionHandlerFactory.php @@ -27,7 +27,7 @@ class SessionHandlerFactory * * @return Psr6SessionHandler */ - public static function get(CacheItemPoolInterface $pool, $config) + public static function get(CacheItemPoolInterface $pool, array $config) { if ($config['use_tagging']) { $pool = new FixedTaggingCachePool(TaggablePSR6PoolAdapter::makeTaggable($pool), ['session']); diff --git a/src/Factory/ValidationFactory.php b/src/Factory/ValidationFactory.php index e98c9ec..a285714 100644 --- a/src/Factory/ValidationFactory.php +++ b/src/Factory/ValidationFactory.php @@ -13,6 +13,7 @@ use Cache\CacheBundle\Bridge\SymfonyValidatorBridge; use Cache\CacheBundle\Cache\FixedTaggingCachePool; +use Cache\Prefixed\PrefixedCachePool; use Cache\Taggable\TaggablePSR6PoolAdapter; use Psr\Cache\CacheItemPoolInterface; @@ -27,12 +28,16 @@ class ValidationFactory * * @return SymfonyValidatorBridge */ - public static function get(CacheItemPoolInterface $pool, $config) + public static function get(CacheItemPoolInterface $pool, array $config) { if ($config['use_tagging']) { $pool = new FixedTaggingCachePool(TaggablePSR6PoolAdapter::makeTaggable($pool), ['validation']); } + if (!empty($config['prefix'])) { + $pool = new PrefixedCachePool($pool, $config['prefix']); + } + return new SymfonyValidatorBridge($pool); } } diff --git a/src/Routing/CachingRouter.php b/src/Routing/CachingRouter.php index 5124b1f..4e4fc8c 100644 --- a/src/Routing/CachingRouter.php +++ b/src/Routing/CachingRouter.php @@ -12,7 +12,7 @@ namespace Cache\CacheBundle\Routing; use Cache\CacheBundle\KeyNormalizer; -use Cache\Taggable\TaggableItemInterface; +use Cache\TagInterop\TaggableCacheItemInterface; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RouterInterface; @@ -166,7 +166,7 @@ private function getCacheItemFromKey($key, $tag) { $item = $this->cache->getItem(KeyNormalizer::noInvalid($key)); - if ($item instanceof TaggableItemInterface) { + if ($item instanceof TaggableCacheItemInterface) { $item->setTags(['router', $tag]); }