I would like to clear my frontend application's cache from an action in my backend application.
How can I achieve this?
During application development, you have to clear the cache in various situations: When you create a new class: Adding a class to an autoloading directory (one of the project’s lib/ folders) is not enough to have symfony find it automatically.
Later, when the item is retrieved, Symfony stores the item automatically in all the missing pools. In applications with many cache keys it could be useful to organize the data stored to be able to invalidate the cache more efficiently. One way to achieve that is to use cache tags.
Listing 18-14 – Clearing Only Selective Parts of the Cache You can also remove files by hand in the cache/ directory, or clear template cache files selectively from the action with the $cacheManager->remove () method, as described inChapter 12 1. We can use $cacheManager->remove () to clear cache after we deployed a new version product.
To get the best of both worlds you may use a chain of adapters. A cache chain combines several cache pools into a single one. When storing an item in a cache chain, Symfony stores it in all pools sequentially. When retrieving an item, Symfony tries to get it from the first pool.
I believe the proper way to do this in symfony 1.2 is as follows:
sfContext::switchTo('frontend'); //switch to the environment you wish to clear
sfContext::getInstance()->getViewCacheManager()->getCache()->clean(sfCache::ALL);
sfContext::switchTo('backend'); //switch back to the environment you started from
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With