Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

No longer recommend to mount the var/cache #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tristanbes
Copy link

@tristanbes tristanbes commented Feb 17, 2020

Hello,

One thing that really is annoying, is problem with Symfony cache, when it shouldn't be an issue when working with Symfony4+.

For now, your template suggests that you should mount the /var/cache so it can be writable. But not only, having it mounted, means it's shared between deployments.

mounts:
    "/var/cache":	
        source: local	
        source_path: "cache"

Why is it bad to share symfony cache between deployments ?

1/ Because you need to clear the cache 2 times. once in the build step and one in the deploy step.
If you ommit to do it in the deploy step, the application will use the cache from the previous deployment even if you cleared the cache in the build step.

2/ Clearing the cache both in the build and deploy is not reliable. When you are making big changes to your Symfony application, sometimes, Symfony loose the ability to remove the cache with the Symfony command because the application is no longer bootable. It's not that rare, and we all experienced it in dev. So I'm not sure we should suffer from it in a PaaS environment.
Exemple of a failure when clearing the cache with Symfony command.

The only workaround is to rm -rf var/cache/* which is bad.

The solution:

STOP sharing the cache between deploys. Since Symfony4, as long as you're calling bin/console cache:warmup the application does not need to write anything by default in the cache folder.
See : https://symfony.com/doc/current/setup/file_permissions.html

@ralt
Copy link

ralt commented Feb 17, 2020

Sorry, according to a Symfony expert I just talked to, this will break e.g. cache pools of the app that use the default config. This probably works for you but unfortunately can't be used as the default base for everyone.

@tristanbes
Copy link
Author

tristanbes commented Feb 17, 2020

cache pools of the app that use the default config

Are you referring to filesystem cache storage ? https://symfony.com/doc/current/components/cache/adapters/filesystem_adapter.html

If yes, it's not by default, it's the slowest way of using the cache. Even in the Symfony demo, they don't mention it: https://github.com/symfony/demo/blob/master/config/packages/cache.yaml

I don't understand your point, can you elaborate please @ralt and eventually post the default config you're referring to ?

@Kingdutch
Copy link

We're running into lots of cache related deploy errors after some bigger changes for a Symfony app we're working now. So I'd be interesting to hear elaboration of the counterpoint of removing our mount for the cache and creating it in the build step.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants