How to clear cache in a cross application, multi server environment in Symfony

Categories : Article, Symfony

Symfony development offers great opportunities for performance optimization. Clearing cache seems to be one of the many ways in Symfony to accelerate performance. Let’s say, your environment may be complicated and it consists of a multi-server environment – either a cluster environment where you use two or more servers that share common storage – for this example, sharing the same database, or a single server with a database. You must device a caching strategy to ensure that you don’t litter your databases with cache entries. Your database is centralized; hence it’s all the more vital for you to clear unnecessary cached data and help your Symfony installation run optimally with good performance.

How to clear cache in a cross application, multi server environment in Symfony

Method 1 for cache clearing and its challenges in a multi server environment

Let’s assume that you use sfFileCache as your caching strategy. Now the challenge is to clear either all or parts of your cache. Well, you might want to use symfony: cc or the sfViewCacheManager. But this essentially will not work due to the following reasons:
This method when used, does not work across applications. If you trigger it from your backend application, it does not allow you to clear cache on the front end.

Secondly, this method works only with the current server that you are working on. It poses a challenge for multi server environments. The other servers in your cluster will still maintain the older version of the cache.

Method 2 for Cross Application cache clearing across multiple servers

How to clear cache in a cross application, multi server environment in Symfony across applications and a centralized database. The main advantage here is that the database is centralized and can access both the servers simultaneously.

You can write all the cache clearing rules to the database and then run a cron job every minute to process the pending rules. This solution works well on highly frequented sites too.

The mbpDistributedCachePlugin optimally serves this purpose. The latest version can be installed to Symfony by symfony plugin:install mbpDistributedCachePlugin.

You can get the detailed instructions for installation here.

Opportunities with Symfony web development could be as simple or as difficult as you make it. Today Symfony offers you a great deal of opportunities to tweak and twist the code and create innovative plug ins and solutions to ensure that your website runs flawlessly without any glitches.

[Total: 2    Average: 3.5/5]

Client Saying

Chad Gundry, the CEO of says that he has worked extensively with Brainvire team since last 6 to 7...
Mr. Chad Gundry
Brainvire completed the job professionally and with an interest to solve the actual root problem I was having. They demonstrated...
Mr. Timothy Drylie
If you're starting a new business or want to upgrade an existing site, I strongly recommend Brainvire. The employees are...
Mr. Manjesh Singh
I am truly happy with Brainvire’s exceptional service. Whenever I had a question they answered it without delay. With extreme...
Mr. Richard Desilva
Brainvire is a professional company with professional developers who understand the problems that we are facing as a company. Outsourcing...
Mr. Clarke Verdel

Latest Happenings

  • 04 Oct 2016
    Brainvire Making great Strides with Symfony Development Services [ + ]
  • 29 Sep 2016
    Brainvire augments its List of Offerings with Magento Sears Integration Services [ + ]