9

Some modules silently turn off caching on certain pages. How is the easiest way to check that this is the case and also identify problematic module?

  • With Boost cache it's simple, there is a html comment at the bottom of the page. with other caches it's a bit more interesting. – Mołot Sep 30 '13 at 9:50
  • @Mołot I'm primarily interested in standard Drupal cache, but instructions to other caches are also appreciate. – user11153 Sep 30 '13 at 9:56
13

The easiest way is probably to inspect the HTTP response headers.

For example, with your browser DOM inspector tool ( e.g Chrome's "Network" tab )

Cache Miss

Here's some sample response headers from drupal.org showing a cache miss. In this case, using Varnish however core Drupal cache also sets similar headers.

cache miss http header

Cache Hit

Here's one showing a standard Drupal cache hit:

cache hit http header

  • But Drupal.org is behind Varnish, isn't it? I can't see X-Cache headers on my Drupal accessed directly. Or I would if the page I'm testing it with was cacheable? – Mołot Sep 30 '13 at 9:53
  • @Mołot I can see the Varnish headers if I'm logged out. – Letharion Sep 30 '13 at 9:55
  • For my Drupal 7 site I indeed see header X-Drupal-Cache: HIT but on my Drupal 6 site I don't see anything. It could be stripped by reverse proxy? – user11153 Sep 30 '13 at 10:02
  • @user11153 yes, D6 doesn't appear to set the X-Drupal-Cache HTTP header there. However D7 does so in _drupal_bootstrap_page_cache – David Thomas Sep 30 '13 at 10:14
  • @DavidThomas So what check cache status in Drupal 6? Are there any alternatives? And thanks for instructions to D7. – user11153 Sep 30 '13 at 10:23
0

Adding cache headers to Drupal 6 default cache

Sadly, it's involving some core hacking.

In file includes/bootstrap.inc change lines from

      // If there is a cached page, display it.
      if ($cache) {
        drupal_page_cache_header($cache);
        // If the skipping of the bootstrap hooks is not enforced, call hook_exit.
        if ($cache_mode != CACHE_AGGRESSIVE) {
          bootstrap_invoke_all('exit');
        }
        // We are done.
        exit;
      }
      // Prepare for non-cached page workflow.
      drupal_page_header();
      break;

to

      // If there is a cached page, display it.
      if ($cache) {
        header('X-Drupal-Cache: HIT');
        drupal_page_cache_header($cache);
        // If the skipping of the bootstrap hooks is not enforced, call hook_exit.
        if ($cache_mode != CACHE_AGGRESSIVE) {
          bootstrap_invoke_all('exit');
        }
        // We are done.
        exit;
      }
      // Prepare for non-cached page workflow.
      header('X-Drupal-Cache: MISS');
      drupal_page_header();
      break;

and the rest of instructions it's exactly as in David's answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.