Symfony: Cross-application cache clearing on distributed servers
While the title might sound a tad complicated, the problem is pretty straight forward:
Your production environment consists of a multi-server set-up (e.g. a cluster, but works on a single server just as well) with a centralised database and you use sfFileCache as your caching strategy (because you don’t want to litter your database with cache entries).
So how would you clear parts or all of the cache? You can’t just use
symfony:cc or the
- It won’t work across applications, e.g. when triggered from your backend application, you won’t be able to clear the cache on your frontend.
- It will only clear the cache on your current server, while the other servers still contain the old cache version.
Along comes our centralised database! The solution we came up with at work was to write all cache clearing rules to the database and then run a cronjob every minute or so to process the pending rules. It already works really well on a highly frequented site we’ve released earlier this year and we’ve decided to package it into a symfony plugin (mbpDistributedCachePlugin).
How to install
You can install the latest stable version via
symfony plugin:install mbpDistributedCachePlugin
or check out the latest version from
svn co http//svn.symfony-project.com/plugins/mbpDistributedCachePlugin/trunk plugins/mbpDistributedCachePlugin
I’ve put detailed installation and usage instruction into the README file (also available here). However, if you should have any questions or suggestions, leave me a comment and I’ll get back to you.