Teach them how to save cache

When a client ask for faster page loads one of the first things that we as Drupal developers can suggest is to enable caching. Basic Page Cache is something that Drupal provides out of the box, it's very easy to implement, and it has a drastic improvement on page load times.

The core cache mechanism in Drupal takes the HTML markup from a page request and stores that in a cache table. The next time this page is requested, instead of running numerous queries to rebuild the page, Drupal just pulls the HTML from the cache table and displays it to the viewer. To enable this setting navigate to the administrative performance page which can be accessed via http://example.com/admin/settings/performance (where your url replaces example.com).

There are 3 caching modes available; Disabled, Normal, and Aggressive. Most sites respond well with Normal Cache and some modules will even go so far to put a warning message that they do not work well with Aggressive Cache. Listen to these messages, and if you try Aggressive Cache and something goes wrong then step back to Normal Cache.

The following setting is "Minimum cache lifetime". It's always wise to set this to something reasonable based upon how often your site gets updated. If you blog post once a day then a "1 day" cache lifetime would seem like a good idea. Then again, if you allow comments on your blog post chances are the page will be cached for 1 day and your viewers will miss out on the comment conversations until the cache is cleared by cron or manually. The description on this field even warns about the effects of this setting. "A larger minimum cache lifetime offers better performance, but users will not see new content for a longer period of time."

Here comes the inevitable conversation:

  • client: I would like pages to load faster.
  • me: Okay, great! We can enable caching.
  • client: How much will that cost.
  • me: Nothing! Drupal is great, it's built into core. BUT, there's one thing that you need to be aware of. When you enable caching new content will not appear on the site until cache is cleared. To do that you just go to the performance page (http://example.com/admin/settings/performance) and click the "Clear cached data" button at the bottom of the form.
  • client: Okay, let's go ahead and turn that on.
  • me: *turns it on*
  • client: Wow, you're right this does load pages faster. Thank You, our users will be so happy! me: It's what I do.
  • ~~~~ 2 Days Later ~~~~
  • client: Dave something is wrong. I just added a post to the site and it won't appear. Some of our users are emailing us telling us that their comments are not appearing. What did you do!!!
  • me: *sigh* *facepalm* *sigh* *think* ("how do I word this nicely") *deep breath* Remember when we enabled caching to improve page loads and I briefly mentioned that caching this data will cause a delay on seeing new content. Well, this is one of those side effects of page caching.
  • client: Oh, that's right. What do I do to resolve that?
  • me: Sorry that must have been my fault. I didn't explain it well enough. All we need to do is go to the performance page (http://example.com/admin/settings/performance) and click the "Clear cached data" button at the very bottom if you want new content to appear immediately.
    Drupal Clear Cache
  • client: *client looks at page*
  • client: Okay thank you. I'll make sure I'll tell our content editor to remember this.

 

So goes the story of Drupal page cache.

Works wonders, even if you only cache a page for "1 min" just need to remember that if something isn't acting correctly, first thing to try is "Clear cached data". However, there is a very nice module called "Cookie Cache Bypass" bundled with 4Kitchens' performance enhanced release of Drupal core called Pressflow that will take care of most of these problems.

// comments

  • David Burns's picture
  • Title
    Chief Executive Officer
    Bio

    David is our co-founder and CEO. His introduction into Drupal was with VB Drupal 4.6, a branch of Drupal core that added a CMS front-end to VBulletin.

    He has diverse expertise in many web related fields such as programming, server performance, search engines, e-commerce and graphic design. He brought these skills to the teams at Sony BMG (now Sony Music entertainment) and LifeTime Digital. When David is not improving the internet he likes to spend time with his son, read books, watch movies, catch up on current events and relax with his pets

// add comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <hr>
  • Lines and paragraphs break automatically.

More information about formatting options