Disabling the cache for reals

Drupal has a very aggressive caching system. While site admins can disable the page cache or CSS compressor very easily, many other caches are not so easy to disable. Think of the menu system, or the theme system, or filter content, or any number of other things that get cached.

In a production site, that's exactly what you want. No Drupal site would be able to handle even moderate traffic if every single registry cache had to be rebuild on every page load. For development, however, it can frequently be a huge pain to have to clear the cache every time you're trying to track down a bug in a menu definition or a CCK field definition.

There's an admin button to clear the cache on the Performance page, but it's not all that useful for intensive debugging. The Devel module (which you are using, right?) offers a handy "clear cache" button, but that doesn't always work if you're, say, debugging a form submission. Fortunately, Drupal makes it easy for us to disable those caches, too, although not through the admin.

The cache system is one of many systems in Drupal that supports swappable include files as a way to offer alternate implementations. As of Drupal 6, Drupal even ships with a cache-install.inc file. As the name suggests, it's intended for use in the installer where you want to totally skip all caching, since there's no database to cache to yet. The code in the file is dead-simple. It's just empty implementations of the standard cache functions, with the net result that nothing ever gets saved to the cache and all cache lookups behave as if nothing is cached. Nice and easy.

Who says the installer gets to have all the fun, though? You can switch your development site to use the installer cache quite easily, thereby bypassing nearly all Drupal caching. To do so, simply uncomment the $conf array defined in settings.php and add the following line:


= array(
// ...
'cache_inc' => 'includes/cache-install.inc',
// ...


That tells Drupal to use the cache-install.inc file instead of cache.inc, thereby disabling the cache entirely across the entire site. (Some systems get build up elsewhere than in the cache tables, like the menu system, so it won't take care of everything, but it does cover a great deal.)

There is, of course, a huge performance hit for doing that. The menu and theme systems must be rescanned on every page load, Views and CCK's registry hooks will get rescanned, all filtered content will have to be refiltered on every page load, etc. You probably don't want to leave it on for all of your dev work, and you absolutely want to remove that line before a site goes live. For debugging certain systems, however, don't forget that Drupal doesn't have to be quite so aggressive.



Make a Free Website with Yola.