Jmsserializerbundle: [BUG] console cache:clear does not clear the cache

Created on 12 Feb 2021  Â·  4Comments  Â·  Source: schmittjoh/JMSSerializerBundle

When I execute

./bin/console cache:clear --env=<ENV>

I expect the bundle's corresponding environment cache to be cleared, but it does not. Instead, I have to manually delete it

rm -rf var/cache/<ENV>/jms_serializer/*

related ticket 734

Most helpful comment

All 4 comments

It's not actually a bug. To cache jms metadata the Metadata\ClassMetadata\FileCache class is used. Symfony doesn't know about this metadata cache and can't clear it.

To clear the jms metadata cache by cache:clear command you need to wrap the built-in Symphony cache with PsrCacheAdapter

# config/packages/jms_serializer.yaml
services:
    jms.metadata_cache:
        class: Metadata\Cache\PsrCacheAdapter
        arguments: ["cache_app_jms_metadata_%kernel.environment%", "@cache.app"]

jms_serializer:
    metadata:
        cache: jms.metadata_cache
  1. This bundle is written specifically for Symfony. Not for Laravel / Yii / Codeigniter / whatever. For Symfony.
  2. This bundle has a cache.

From these two facts, it's too obvious to expect the bundle cache to be cleared by a standard Symfony cache clearing command. You don't run a separate cache clearing command for each bundle you have in your project.

But the bundle cache can neither be cleared by Symfony's standard cache clearing command nor the bundle has its own command to clear the cache. The only workaround is to write an undocumented config modification.

Now, I would really appreciate if you could logically explain to me how is this not a bug.

thank you

Was this page helpful?
0 / 5 - 0 ratings