Skip to content

Commit eecffff

Browse files
lstrojnynicolas-grekas
authored andcommitted
[Cache] Allow ISO 8601 time intervals to specify default lifetime
1 parent e509071 commit eecffff

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

DependencyInjection/Configuration.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,10 @@ private function addCacheSection(ArrayNodeDefinition $rootNode)
10401040
->end()
10411041
->scalarNode('tags')->defaultNull()->end()
10421042
->booleanNode('public')->defaultFalse()->end()
1043-
->integerNode('default_lifetime')->end()
1043+
->scalarNode('default_lifetime')
1044+
->info('Default lifetime of the pool')
1045+
->example('"600" for 5 minutes expressed in seconds, "PT5M" for five minutes expressed as ISO 8601 time interval, or "5 minutes" as a date expression')
1046+
->end()
10441047
->scalarNode('provider')
10451048
->info('Overwrite the setting from the default provider for this adapter.')
10461049
->end()

Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@
283283
<xsd:attribute name="adapter" type="xsd:string" />
284284
<xsd:attribute name="tags" type="xsd:string" />
285285
<xsd:attribute name="public" type="xsd:boolean" />
286-
<xsd:attribute name="default-lifetime" type="xsd:integer" />
286+
<xsd:attribute name="default-lifetime" type="xsd:string" />
287287
<xsd:attribute name="provider" type="xsd:string" />
288288
<xsd:attribute name="early-expiration-message-bus" type="xsd:string" />
289289
<xsd:attribute name="clearer" type="xsd:string" />

Tests/DependencyInjection/Fixtures/php/cache.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
'provider' => 'app.cache_pool',
2323
],
2424
'cache.def' => [
25-
'default_lifetime' => 11,
25+
'default_lifetime' => 'PT11S',
26+
],
27+
'cache.expr' => [
28+
'default_lifetime' => '13 seconds',
2629
],
2730
'cache.chain' => [
2831
'default_lifetime' => 12,

Tests/DependencyInjection/Fixtures/xml/cache.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<framework:pool name="cache.bar" adapter="cache.adapter.doctrine" default-lifetime="5" provider="app.doctrine_cache_provider" />
1212
<framework:pool name="cache.baz" adapter="cache.adapter.filesystem" default-lifetime="7" />
1313
<framework:pool name="cache.foobar" adapter="cache.adapter.psr6" default-lifetime="10" provider="app.cache_pool" />
14-
<framework:pool name="cache.def" default-lifetime="11" />
14+
<framework:pool name="cache.def" default-lifetime="PT11S" />
15+
<framework:pool name="cache.expr" default-lifetime="13 seconds" />
1516
<framework:pool name="cache.chain" default-lifetime="12">
1617
<framework:adapter name="cache.adapter.array" />
1718
<framework:adapter name="cache.adapter.filesystem" />

Tests/DependencyInjection/Fixtures/yml/cache.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ framework:
1616
default_lifetime: 10
1717
provider: app.cache_pool
1818
cache.def:
19-
default_lifetime: 11
19+
default_lifetime: PT11S
20+
cache.expr:
21+
default_lifetime: 13 seconds
2022
cache.chain:
2123
default_lifetime: 12
2224
adapter:

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
6262
use Symfony\Component\Validator\Mapping\Loader\PropertyInfoLoader;
6363
use Symfony\Component\Workflow;
64+
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
6465
use Symfony\Component\Workflow\WorkflowEvents;
6566
use Symfony\Contracts\Cache\CacheInterface;
6667
use Symfony\Contracts\Cache\TagAwareCacheInterface;
67-
use Symfony\Component\Workflow\Metadata\InMemoryMetadataStore;
6868

6969
abstract class FrameworkExtensionTest extends TestCase
7070
{
@@ -1333,7 +1333,8 @@ public function testCachePoolServices()
13331333
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.bar', 'cache.adapter.doctrine', 5);
13341334
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.baz', 'cache.adapter.filesystem', 7);
13351335
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.foobar', 'cache.adapter.psr6', 10);
1336-
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 11);
1336+
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.def', 'cache.app', 'PT11S');
1337+
$this->assertCachePoolServiceDefinitionIsCreated($container, 'cache.expr', 'cache.app', '13 seconds');
13371338

13381339
$chain = $container->getDefinition('cache.chain');
13391340

Tests/Functional/app/CachePools/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
imports:
22
- { resource: default.yml }
33

4+
parameters:
5+
env(LIFETIME_INTERVAL): 'PT10S'
6+
env(LIFETIME_EXPRESSION): '13 seconds'
7+
48
framework:
59
cache:
610
pools:
711
cache.pool1:
812
public: true
913
adapter: cache.system
14+
default_lifetime: '%env(LIFETIME_EXPRESSION)%'
1015
cache.pool2:
1116
public: true
1217
adapter: cache.pool3
18+
default_lifetime: '%env(LIFETIME_INTERVAL)%'
1319
cache.pool3:
1420
clearer: ~
1521
cache.pool4:

0 commit comments

Comments
 (0)