symfony caching – cross-application cache clearing

I’m writing a webapp that has an api application, and a frontend application. The frontend supports caching, since it’s providing RSS feeds that might be read quite frequently, and don’t change often. The currently timeout is set to 12 hours. The API allows the user to change aspects of the RSS feeds that will change the contents of the feed so much that it could be totally different, and 12 hours is too long for the user to wait.

What I needed to do was clear the frontend cache, but from within the API application. I found this post that described how to do it in symfony 1.2, and it works just great in 1.4! Here’s the post: clearing symfony cache for another application.

Here’s the code snippet that I ended up using:

// Save any changes, if any were made, and clear the frontend RSS cache for
// this feed.
if ($changes == true)
// Clear cache, if it's turned on.
sfContext::switchTo('frontend'); //switch to the environment you wish to clear
sfContext::getInstance()->getViewCacheManager()->remove('static/rss?id=' . $wc->getId());
sfContext::switchTo('api'); //switch back to the environment you started from