Drupal 6 Development Can Be A Caching Pain

druplicon_small.pngDrupal provides some great caching tools to improve page loading performance. Production sites see huge speed increases because of caching. But, when a site is being developed caching can quickly turn into a nightmare. For example, when you add a new theme override function your to template.php file it isn't picked up right away and you may end up banging your head wondering what's going on. Or, when your developing filter code your filtered content may be cached. Going to the performance setting page and clearing the cache is annoying and a work flow problem. So, let's look at a couple simple solutions that can make development a little easier and less painful.

Cache Disable Module

Drupal wiz kid Dmitri Gaskin created the Cache Disable module which does just as it's name suggests. While some solutions clear the cache on every page load this module disables it. During development this is a great tool to use.

Clearing The Cache In Your Code

If you just want to clear part of the cache during development you can use some code snippets to do just that. For example, if you are developing a theme and just don't want the theme information to stay in the cache you could call drupal_rebuild_theme_registry() in your theme to rebuild the theme cache on every page load. A simple way to do this would be to add the following code snippet to the bottom of your page.tpl.php file.


Other cache clearing functions you can use are cache_clear_all(), menu_rebuild(), and drupal_flush_all_caches(), which clears all possible caches including those that contributed modules use with the caching system.

Once the sites are ready for production these functions or modules we added should be removed so we can get all the caching benefits.

Devel module

I guess that while building sites, you will often have the devel module enabled. This module provides a "clear cache" link in its primary block. I'm sure you know that, but I thought that it would be worth noting for visitors.

By the way, I heard about Drupal through your podcast. Now, I'm doing it on the side for lots of churches, friends, businesses, etc. Thanks for the inspiration.


You spelled menu_rebuild as menu_reuild.
Besides that, thanks for linking to my module.

Additionally, the top of template.php would be a better place to add the drupal_rebuild_theme_registry().


Thanks for pointing out the typo and for the good suggestion. Putting drupal_rebuild_theme_registry() at the top of the template.php file would be better for work flow. It would rebuild the template registry for that page load rather than the next one.

You could do this...

While these are good ideas, I heartily believe they truly degrade my Drupal experience. To be a real day of working on Drupal, you need to encounter problems which make you punch yourself in the face over and over again while trying to figure out why this stupid (and awesome) system is not working how you expect.

Maybe someday, I'll put these into practice if I want to make Drupal "easy to use". But until then, I'll just keep punching myself in the face and going to the performance page to find the 'clear cache' button (when I remember it's there).

Getting cache to work right is a hard thing

There are only two hard things in Computer Science: cache invalidation and naming things.
Phil Karlton's Wise Saying

Surely it is a hard thing, but if you really need good performance and try hard, you can achieve great results.

My advice from experience: if your website is complex, be prepared to write entire scripts for invalidating parts of cache depending on what is changed in the database.

It's really a useful stuff

It's really a useful stuff for me. I'm struggling with drupal's cache for weeks. Thanks a lot!

From the looks of the site

From the looks of the site it's using CCK and Views to create the site. The homepage is a view. The link to spreadshirt.com is a CCK field and the Image is just in the body. I'm surprised that's not a CCK field, too. For the sorting Taxonomy looks to be used.