Skip to content

[FrameworkBundle] Cache pool namespace added to configuration #20483

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

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
->scalarNode('adapter')->defaultValue('cache.app')->end()
->booleanNode('public')->defaultFalse()->end()
->integerNode('default_lifetime')->end()
->scalarNode('namespace')->end()
->scalarNode('provider')
->info('The service name to use as provider when the specified adapter needs one.')
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
<xsd:attribute name="adapter" type="xsd:string" />
<xsd:attribute name="public" type="xsd:boolean" />
<xsd:attribute name="default-lifetime" type="xsd:integer" />
<xsd:attribute name="namespace" type="xsd:string" />
<xsd:attribute name="provider" type="xsd:string" />
<xsd:attribute name="clearer" type="xsd:string" />
</xsd:complexType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'cache.foo' => array(
'adapter' => 'cache.adapter.apcu',
'default_lifetime' => 30,
'namespace' => 'foo_',
),
'cache.bar' => array(
'adapter' => 'cache.adapter.doctrine',
Expand All @@ -19,6 +20,7 @@
'cache.foobar' => array(
'adapter' => 'cache.adapter.psr6',
'default_lifetime' => 10,
'namespace' => 'foobar_',
'provider' => 'app.cache_pool',
),
'cache.def' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

<framework:config>
<framework:cache>
<framework:pool name="cache.foo" adapter="cache.adapter.apcu" default-lifetime="30" />
<framework:pool name="cache.foo" adapter="cache.adapter.apcu" default-lifetime="30" namespace="foo_" />
<framework:pool name="cache.bar" adapter="cache.adapter.doctrine" default-lifetime="5" provider="app.doctrine_cache_provider" />
<framework:pool name="cache.baz" adapter="cache.adapter.filesystem" default-lifetime="7" />
<framework:pool name="cache.foobar" adapter="cache.adapter.psr6" default-lifetime="10" provider="app.cache_pool" />
<framework:pool name="cache.foobar" adapter="cache.adapter.psr6" default-lifetime="10" namespace="foobar_" provider="app.cache_pool" />
<framework:pool name="cache.def" default-lifetime="11" />
</framework:cache>
</framework:config>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ framework:
cache.foo:
adapter: cache.adapter.apcu
default_lifetime: 30
namespace: 'foo_'
cache.bar:
adapter: cache.adapter.doctrine
default_lifetime: 5
Expand All @@ -14,6 +15,7 @@ framework:
cache.foobar:
adapter: cache.adapter.psr6
default_lifetime: 10
namespace: 'foobar_'
provider: app.cache_pool
cache.def:
default_lifetime: 11
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,10 @@ public function testCachePoolServices()
{
$container = $this->createContainerFromFile('cache');

$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foo', 'cache.adapter.apcu', 30);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foo', 'cache.adapter.apcu', 30, 'foo_');
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.bar', 'cache.adapter.doctrine', 5);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.baz', 'cache.adapter.filesystem', 7);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foobar', 'cache.adapter.psr6', 10);
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foobar', 'cache.adapter.psr6', 10, 'foobar_');
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11);
}

Expand Down Expand Up @@ -717,7 +717,7 @@ private function assertVersionStrategy(ContainerBuilder $container, Reference $r
}
}

private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $container, $id, $adapter, $defaultLifetime)
private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $container, $id, $adapter, $defaultLifetime, $namespace = null)
{
$this->assertTrue($container->has($id), sprintf('Service definition "%s" for cache pool of type "%s" is registered', $id, $adapter));

Expand All @@ -732,6 +732,11 @@ private function assertCachePoolServiceDefinitionIsCreated(ContainerBuilder $con
$this->assertTrue(isset($tag[0]['default_lifetime']), 'The default lifetime is stored as an attribute of the "cache.pool" tag.');
$this->assertSame($defaultLifetime, $tag[0]['default_lifetime'], 'The default lifetime is stored as an attribute of the "cache.pool" tag.');

if (null !== $namespace) {
$this->assertTrue(isset($tag[0]['namespace']), 'The namespace is stored as an attribute of the "cache.pool" tag.');
Copy link
Member

@nicolas-grekas nicolas-grekas Nov 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this line: if the key does not exist, phpunit will throw a exception anyway on the next line.

$this->assertSame($namespace, $tag[0]['namespace'], 'The namespace is stored as an attribute of the "cache.pool" tag.');
}

$parentDefinition = $poolDefinition;
do {
$parentId = $parentDefinition->getParent();
Expand Down