Symfony2 Delete Cache on One Single File

How to delete cache on one single file with Symfony2

Sometimes in production environement you've got to quickly patch your code on one single file, but you cannot empty the whole cache because users are connected and using the web site.
So to delete cache on a single file with Symfony2 you've got to locate the good file in the cache folder to delete it.
If the file is controller:
Browse through your project file and look for


You can just delete it, don't worry because the cache system will recreate the new file the next time the controller is called throught an user interaction with it through the browser.
If it is a twig file:
To find the twig file you want to delete just run the find command to search inside files and in the argument include the complete twig file name with the path included:

find | xargs grep -r "AcmeBundlenameBundle:Default:twigname.html.twig"

look into the path of founded files and you'll see something like


well there is the file to delete. Just delete it it will be recreated when needed.
It's just that deleting the whole cache is better for coherence reasons there may be side effects, so do it to your own risk.