How does caching work in Drupal?

In my experience, there seems to be a lot of misunderstanding how Drupal caching works. I'm not talking about advanced caching mechanisms like Varnish, APC or memcache here, I'm talking about the core Drupal caching: page cache and block cache which are available in Drupal 7 core. Drupal 6 is similar but works a but differently because page caching was simplified for Drupal 7 (e.g. aggresive mode is now a available as a settings.php var) and the entire system also has become pluggable.

Everybody knows this screen and the settings. But what do they exactly mean? What difference do they actually make? What do they do? Here is an attempt to explain the settings at '/admin/config/development/performance'.

Page Caching:
  • If enables, page caching will only be used for anonymous users.
  • If you enable page caching, the entire HTML of each page will be stored in the database. This significantly reduces the amount of queries needed.
  • This automatically means that blocks will also get cached, disregarded their own cache settings.
  • If Varnish is configured, this will also enable varnish caching
  • The page cache max-age will be used (see below) for each page.
  • You can check the "X-Drupal-Cache" HTTP header to check if this cache is HIT.
Block Caching:
  • If you enable block caching, without enabling page caching, the block cache settings will be used (for anonymous and authenticated).
  • The defaults for most blocks is "don't cache" because that is the default for blocks who don't have their cache settings specifically declared.
  • You can use block_cache_alter module to set this for each block.
  • When it's block created by Views, you can set the cache settings for a block in Views.
Minimum Cache Lifetime:
  • This is the amount of time before the page cache is cleared.
  • Page caches are cleared on each cron run
  • Be warned: incorrect settings of your cron and this setting might kill your website performance.
Expiration of Cached Page:
  • This only applies for external caching mechanisms, for example your browser cache or Varnish.
  • It sets the Cache-Control max-age value in the HTTP-HEADERS.
  • This setting only takes effect when page caching is turned on.

Comments

  1. Hi
    Thanks for your post, this is really helpful. I am getting a problem with drupal cache. When I changed the status and name of file in database and then load file programatically then it is not reflecting on front end. after clearing cache it is reflecting. Do you have any idea about this problem? I have disabled "cache for anonymous user" and minimum, expiration select box are set to "none". I am using drupal 7.15 version.

    ReplyDelete
  2. Nice article, thanks for clarifying that. Would be great if you could elaborate on how the caching differs between Drupal 6 & 7. Thanks & Cheers!!

    ReplyDelete
  3. Wow great post about Drupal Development. Drupal is best CMS. Hire a Drupal Programmer from us as we hire talents who are capable to think out-of-the-box, with a strong dedication towards constant learning and understanding the fine prints of Drupal in every possible way.

    ReplyDelete
  4. thanks terry. I'll continue this.

    ReplyDelete
  5. Hey hi..i just go through the site and post also..really helpful and informative. I think people should go through it. Thank you for sharing.

    Drupal Web Development

    ReplyDelete
  6. In my experience, there seems to be a lot of misunderstanding how Drupal caching works. I'm not talking about advanced caching mechanisms like Varnish, APC or memcache here, I'm talking about the core Drupal caching: page cache and block cache which are available in Drupal 7 core. Drupal 6 is similar but works a but differently because page caching was simplified for Drupal 7 and the entire system also has become pluggable.

    Drupal Web Development

    ReplyDelete
  7. Really a great tip. really thanks very much drupal

    ReplyDelete
  8. I wish this finds you well, have been catching up on all of your before posts! Excellent information!
    Website Design Companies Bangalore

    ReplyDelete

Post a Comment

Popular posts from this blog

ubuntu package installation

Drupal Bootstrap Database

How to fix 500 internal privoxy error