Skip to content

Make sure all types of cache supports prefix and tagging #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Cache/Recording/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/CacheExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'))
Expand Down
5 changes: 5 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -227,6 +230,8 @@ private function addRouterSection()
->scalarNode('service_id')
->isRequired()
->end()
->booleanNode('use_tagging')->defaultTrue()->end()
->scalarNode('prefix')->defaultValue('')->end()
->end();

return $node;
Expand Down
7 changes: 6 additions & 1 deletion src/Factory/DoctrineBridgeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
44 changes: 44 additions & 0 deletions src/Factory/RouterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of php-cache\cache-bundle package.
*
* (c) 2015-2015 Aaron Scherer <aequasi@gmail.com>, Tobias Nyholm <tobias.nyholm@gmail.com>
*
* 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 <tobias.nyholm@gmail.com>
*/
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);
}
}
2 changes: 1 addition & 1 deletion src/Factory/SessionHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
7 changes: 6 additions & 1 deletion src/Factory/ValidationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/Routing/CachingRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}

Expand Down