feature #18561 [FrameworkBundle] Fallback to default cache system in production for serializer (tgalopin)
This PR was merged into the 3.1-dev branch.
Discussion
----------
[FrameworkBundle] Fallback to default cache system in production for serializer
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
In the same idea as https://github.com/symfony/symfony/pull/18544, this PR proposes a default fallback to filesystem cache for the serializer if the APC cache is not enabled in production. In other words, if the following part of `config_prod.yml` file is not uncommented, the filesystem will be used:
``` yaml
#framework:
# serializer:
# cache: serializer.mapping.cache.doctrine.apc
```
Commits
-------
4f0b8be
[FrameworkBundle] Fallback to default cache system in production for serializer
This commit is contained in:
commit
51d075a51b
@ -513,7 +513,7 @@ class Configuration implements ConfigurationInterface
|
||||
->canBeEnabled()
|
||||
->children()
|
||||
->booleanNode('enable_annotations')->defaultFalse()->end()
|
||||
->scalarNode('cache')->end()
|
||||
->scalarNode('cache')->defaultValue('serializer.mapping.cache.symfony')->end()
|
||||
->scalarNode('name_converter')->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -982,7 +982,7 @@ class FrameworkExtension extends Extension
|
||||
|
||||
$chainLoader->replaceArgument(0, $serializerLoaders);
|
||||
|
||||
if (isset($config['cache']) && $config['cache']) {
|
||||
if (!$container->getParameter('kernel.debug')) {
|
||||
$container->setParameter(
|
||||
'serializer.mapping.cache.prefix',
|
||||
'serializer_'.$this->getKernelRootHash($container)
|
||||
|
@ -25,6 +25,10 @@
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="cache.pool.serializer" parent="cache.adapter.local" public="false">
|
||||
<tag name="cache.pool" clearer="cache.default_pools_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="cache.adapter.apcu" class="Symfony\Component\Cache\Adapter\ApcuAdapter" abstract="true">
|
||||
<argument /> <!-- namespace -->
|
||||
<argument /> <!-- default lifetime -->
|
||||
|
@ -38,6 +38,10 @@
|
||||
</service>
|
||||
|
||||
<!-- Cache -->
|
||||
<service id="serializer.mapping.cache.symfony" class="Symfony\Component\Cache\DoctrineProvider" public="false">
|
||||
<argument type="service" id="cache.pool.serializer" />
|
||||
</service>
|
||||
|
||||
<service id="serializer.mapping.cache.doctrine.apc" class="Doctrine\Common\Cache\ApcCache" public="false">
|
||||
<call method="setNamespace">
|
||||
<argument>%serializer.mapping.cache.prefix%</argument>
|
||||
|
@ -221,6 +221,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
|
||||
'serializer' => array(
|
||||
'enabled' => false,
|
||||
'enable_annotations' => false,
|
||||
'cache' => 'serializer.mapping.cache.symfony',
|
||||
),
|
||||
'property_access' => array(
|
||||
'magic_call' => false,
|
||||
|
@ -66,7 +66,7 @@ $container->loadFromExtension('framework', array(
|
||||
'serializer' => array(
|
||||
'enabled' => true,
|
||||
'enable_annotations' => true,
|
||||
'cache' => 'serializer.mapping.cache.apc',
|
||||
'cache' => 'serializer.mapping.cache.doctrine.apc',
|
||||
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case',
|
||||
),
|
||||
'ide' => 'file%%link%%format',
|
||||
|
@ -40,6 +40,6 @@
|
||||
</framework:translator>
|
||||
<framework:validation enabled="true" cache="validator.mapping.cache.doctrine.apc" />
|
||||
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
|
||||
<framework:serializer enabled="true" enable-annotations="true" cache="serializer.mapping.cache.apc" name-converter="serializer.name_converter.camel_case_to_snake_case" />
|
||||
<framework:serializer enabled="true" enable-annotations="true" cache="serializer.mapping.cache.doctrine.apc" name-converter="serializer.name_converter.camel_case_to_snake_case" />
|
||||
</framework:config>
|
||||
</container>
|
||||
|
@ -52,7 +52,7 @@ framework:
|
||||
serializer:
|
||||
enabled: true
|
||||
enable_annotations: true
|
||||
cache: serializer.mapping.cache.apc
|
||||
cache: serializer.mapping.cache.doctrine.apc
|
||||
name_converter: serializer.name_converter.camel_case_to_snake_case
|
||||
ide: file%%link%%format
|
||||
request:
|
||||
|
@ -449,7 +449,7 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
|
||||
$this->assertCount(1, $argument);
|
||||
$this->assertEquals('Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader', $argument[0]->getClass());
|
||||
$this->assertEquals(new Reference('serializer.mapping.cache.apc'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
|
||||
$this->assertEquals(new Reference('serializer.mapping.cache.doctrine.apc'), $container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
|
||||
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.normalizer.object')->getArgument(1));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user