Drupal, like most CMSes uses cache intensively to speed things up. In a production site that is exactly what you what. However when developing, cache can cause you much pain.

If your an expert in drupal you probably already realized when you need to clear the cache in order to see changes and when not too. the developer module even makes it quite easy to do. However for me, and I am quite sure to quite a lot of other people it is not that clear.

“Wait”, you might say. “Drupal has a disable cache setting”. You would be right to say that. Only it doesn’t completely disable the cache, only part of the cache, namely the page caching. To truly disable cache you need to do a bit of a hacking to the cache code. Yes I know they say to never hack core (cache is part of the core drupal release). for me this was worth it. I figure as long as you remember its there and don’t use it in production you should be fine. The following piece of code needs to be added in include/cache.inc. There are two functions there that you need to edit:

  • cache_get
  • cache_set

In cache_get place the code right after the global $user. In cache_set place it at the start of the function. Here is the code that you need to add.

if(variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED) {
return 0;
}

Kudos for this hack goes to Rolf van de Krol. Cheers mate.

§168 · May 29, 2009 · guide, programming, web · Tags: , , , , · [Print]

5 Comments to “How to truly disable drupal cache”

  1. intuited says:

    Hey, thanks for this tip. Not sure if this was where I originally found it, but I’ve been using it for a while now and haven’t had any problems until recently. I was a bit mystified as to why I couldn’t export a CCK content type; it turns out it was because of this. Basically this hack breaks the multipart form system: Drupal looks for a cached form, and because of this hack thinks that the lookup failed, and draws the conclusion that this is a fresh presentation of the form.
    I’m surprised I haven’t run into other problems because of this.
    Anyway it did seem to make things speed up a bit, but I guess I’ll unpatch it.
    Thanks!

  2. intuited says:

    Did I say speed up? Well you know what I meant. Cheers

  3. Shaurya says:

    It shouldn’t but this breaks a number of things – node and user deletes, module uninstallations, any sort of ajax form usage like adding extra options to polls and additional cck images etc.

    • Kfir says:

      It does break some stuff in drupal. Which is why this should only be used in testing, and then also only in very specific situations.

  4. compartment that has 1200 cubic-inch capacity- Minor zip pockets for holding modest things- Laptop computer sleeve north face uk domestic normally six or 7 hundred of Nike, Adidas, only spends seventy to eighty in the America,

Leave a Reply