Posted by & filed under Development, symfony.

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 sfViewCacheManager because:

  • 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// 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.

2 Responses to “Symfony: Cross-application cache clearing on distributed servers”

  1. JevieBui

    Hi, found your plugin very useful but Hi, I have problem when executing command:

    > php symfony distributed-cache:register-server

    This is a error:

    PHP Fatal error: Call to undefined method ServerTable::getOrCreateOneByName() in /var/www/deploy/jobeet_hungbq/plugins/mbpDistributedCachePlugin/lib/task/RegisterServerTask.class.php on line 60

    Fatal error: Call to undefined method ServerTable::getOrCreateOneByName() in /var/www/deploy/jobeet_hungbq/plugins/mbpDistributedCachePlugin/lib/task/RegisterServerTask.class.php on line 60

    Hope you will reply me soon !

    • Burgi

      Hi Jevie,
      I’m afraid I don’t work for this company anymore and won’t be investing any more time in symfony1 either. You’re on your own buddy.

      P.S.: For something a bit more future-proof, check out Symfony2!