Speed up a Drupal web site by enabling page caching

Technologies: Drupal 5+

Speed up page load times by saving commonly-used web pages in Drupal’s page cache. Cached pages are faster to send to site visitors.

This article is part of the Essential steps to speed up a Drupal web site article series. Other articles in this series look at improving the performance of PHP and MySQL and ways to adjust your page layout to improve web site performance.

How to enable Drupal page caching

Drupal&'s page cache is disabled by default. Enable it to speed up page load times substantially.

  1. Log in as your Drupal site's administrator.
  2. Go to the Administer » Site configuration » Performance page.
  3. Check the Normal checkbox for the  Caching mode.
  4. Set the Minimum cache lifetime to 1 day.
  5. Click the Save configuration button

What does it do?

To build the web page, Drupal queries the site’s database to get menus, blocks, user information, and the main content of a page. All of this is formatted by the site’s modules to create the HTML page that’s returned to the visitor.

By default, Drupal builds a new web page for every visitor. If two visitors ask for the same page, Drupal builds the page twice. To save time, the page cache enables Drupal to save each page the first time it is built. On the second visit, Drupal returns the saved page instead of building it all over again.

The page cache is empty when it is first enabled. As visitors view the site’s pages, Drupal builds and saves the pages into the cache. After awhile, the cache will have most of the site’s popular pages and the site will feel much faster.

Pages in the cache expire and are thrown out after the Minimum cache lifetime. Changes to a cached page will not be seen by visitors until the page expires. To see changes sooner, set the lifetime to a shorter value.

The Caching mode also has an Aggressive setting. When enabled, this slightly improves page load times but it can break some modules. Use it at your own risk.

How well does it work?

I benchmarked the effect of page caching on two representative test sites: a simple Drupal site with just the basic modules, and a complex site with lots of modules (see my Specifications for Drupal web site testing). Both sites have no other performance improvements (e.g., no file compression, no PHP script cache, no MySQL query cache, and no Drupal CSS file aggregation). Load times are for each site’s home page, including HTML, CSS, JavaScript, and images. Tests simulated a web page uploaded over a 64Kbps cable modem, such as that used to serve small web sites from a home or small business.

With page caching, page load times improved by 30-40%.

Total page load time

Web pages for the complex site include more blocks and require more time to build than for the simple site. Caching these complex pages therefore has a more substantial impact than for the simple site. In general, the more complex the site, the greater the benefit from enabling page caching.

When doesn’t it work?

Drupal’s page cache only works for anonymous visitors (people who don’t log in to the site). For many web sites, nearly all traffic is from anonymous visitors and the page cache is an important way of speeding up the site.

However, the page cache is disabled for logged-in visitors. Each of these visitors may have unique account permissions and preferences that shape how Drupal builds web pages. Since each logged-in visitor may be different, Drupal must generate a custom page for each one. It cannot use the page cache.

Conclusions

Drupal’s page cache works well for anonymous visitors and it is a useful way to improve web site performance. Because logged-in visitors do not benefit from the page cache, it is important to also look at other performance improvements, such as file compression and Drupal’s CSS file aggregation.

Further reading

Comments

Very very Nice Article !

First of all,I would like to thank for fantastic article.

I didn't find any where this kind of articles regarding Drupal performance.

Its very crystal clear :)

"Pages in the cache expire

"Pages in the cache expire and are thrown out after the Minimum cache lifetime."

This should be "Pages are in the cache at least the Minimum cache lifetime."

Re: Pages in the cache expire

True. Thanks for the clarification.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

Nadeau software consulting
Nadeau software consulting