0

To deploy, I 'git pull' then 'bin/console cache:clear' to see the updates to my website.

It works, but I don't want to lose MY cache pool's data when this happens. (I cache results to 3rd party api calls)

I expected the symfony command to clear it's own cache stores only and not the cache items I've submitted since they are still valuable to me after I clear the symfony cache to deploy new code.

Q1: How can I clear all the caches except my app's cache pool 'api_call_cache_pool' below?

Q2: Is there a different cache clear call I should use instead of 'bin/console cache:clear'?

Q3: Would api_call_cache_pool not be cleared if it's adapter was Redis instead of filesystem?

framework:
    cache:

        directory: '%kernel.cache_dir%/pools'   

        app: cache.adapter.filesystem
        system: cache.adapter.system

        pools:
            api_call_cache_pool:
                adapter: cache.adapter.filesystem
                default_lifetime: 6000
                tags: true
castacked
  • 1
  • 1

2 Answers2

0

As cache:clear will clear all your caches, I would reccomend to create a script by leveraging the php bin/console cache:pool:list and exclude what you want to exclude (api_call_cache_pool in your example).

I'm not sure why a "blacklist" policy can't be applied here.

(Or, maybe, use cache.system_clearer and cache.app_clearer can be enough; you should try by yourself)

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • Does not look like cache:clear will clear all cache including all the pools though. I cannot find any document regarding that. Do you have any additional information that can confirm it? I tried on my app and cache:clear does not seem to clear pools at all. – mr1031011 Jan 06 '21 at 06:50
  • @mr1031011 "_The global clearer clears all the cache items in every pool._ The system cache clearer is used in the bin/console cache:clear command. The app clearer is the default clearer." from [docs](https://symfony.com/doc/current/cache.html#clearing-the-cache) – DonCallisto Jan 07 '21 at 06:59
  • @DonCallisto `cache:clear` will not clear all caches. Per the quoted documentation, it only uses the cache.system_clearer. – Joe Devine Jul 07 '23 at 20:21
0

From the docs for the version of Symfony relevant to your question:

To clear the cache you can use the bin/console cache:pool:clear [pool] command. That will remove all the entries from your storage and you will have to recalculate all the values. You can also group your pools into "cache clearers". There are 3 cache clearers by default:

  • cache.global_clearer
  • cache.system_clearer
  • cache.app_clearer

The global clearer clears all the cache items in every pool. The system cache clearer is used in the bin/console cache:clear command. The app clearer is the default clearer.

This documentation also applies to the current version of Symfony at the time of this post (6.2).

You can see here that it states that the cache:clear command only clears the system cache (via the cache.system_clearer). So with your setup, it should not clear your api_call_cache_pool pool when cache:clear runs. Therefore, you shouldn't have to make any changes.

If you wanted to your deployment script to be more explicit you could run cache:pool:clear cache.system_clearer instead of cache:clear.

Joe Devine
  • 161
  • 11