The ‘drush cc all’ syndrome
If you use drush and code modules/templates in Drupal you know the symptom: add a new template file, add a hook to your module, pretty much change a few things in your code and you issue a drush cc all ‘just in case’. Drupal has an extensive cache system which is your friend but unfortunately when coding you often have to clear it so that the new changes can be detected. This constant ‘clear all caches’ can really slow you down. On large sites a drush cc all can take as long as 15-20 seconds to complete. If you are not sure your overriding the correct template or hook then it can become a little annoying to waste so much time.
As you probably know, Drupal has more than one cache. Wouldn’t it be great if you could just clear the cache which you know needs to be cleared and avoid clearing the others which don’t have an impact? It turns out you can! The only problem is knowing what modifications go into what cache. You could spend some time going through core but it’s probably easier to do it by trial and error. Because of this issue I decided to experiment a little in my latest projects and waste a little more time to compile a list of drush cc commands and when you should issue them. Here’s what I have so far:
- modify or add your hook_menu() module function
- modify or add your hook_menu_alter()
$ drush cc registry
- modify or add your hook_form_alter()
- Add a new hook to your module. For example: hook_node_save()
$ drush cc theme_registry
- Add a new .tpl.php file to a theme theme
$ drush cc css-js
- If you have turned on CSS and JS aggregation you can use this to regenerate the aggregated CSS and JS.
That’s what I have so far. It’s been a real time saver for me. If you have other drush cc xxxx commands to share leave a note and I’ll add them to the post. Maybe later I’ll add a page to the drush page at drupal.org
- Thanks to Hjalmar from Nodeone for the drush cc css-js tip!