Resources

Caching overview

One of Drupal’s key strengths is that it can dynamically generate content, serving up different content depending on the user and the context. To dynamically generate the page sent to the browser, a series of complex events must run, such as the following:

  • Establishing a database connection

  • Loading settings and modules

  • Initializing a user session

  • Mapping the URL to a PHP page callback function to run the application’s business logic

  • Collecting the elements surrounding the main content of the page

Most of the steps run every time a page renders, and can take more time than a basic web server to serve a static page.

An effective caching strategy can greatly improve performance by storing pages, page elements, and other resources, so a cached version of a page or page element renders rather than a newly generated version. Proper use of caches greatly improves your website’s performance. Ensure you develop a caching strategy best meeting the needs of your website. Although people consider caching as inconvenient and annoying, you must consider caching to improve website performance.

Caching by stack level

To properly configure the largest pieces of caching for your website, you can build several caching types covering the different levels of the stack, including the application, component, and page layers.

Application caching

A large number of applications work with Drupal to do heavy caching. The applications are critical to the response time of sizeable websites.

Component caching

User-facing components, such as views and panels, cache information in smaller chunks instead of an entire page. Improving the rendering of a single view or panel, when the component is used on various pages, can generally reduce time. Component-level caching is typically disabled by default, though you can turn component-level caching on with some easy to use configuration changes. For the best results, identify blocks, panels, and views remaining the same across your website, and then cache them aggressively.

Page caching

Page caching is the most efficient type of caching. Instead of generating pages dynamically with Drupal bootstrap, your server can display static HTML pages to users. The entire page is cached, stored and delivered to a user.

Unless your website needs fast content updates (such as news updates, stock monitoring, or weather reports), you can get the best results with stronger caching methods. Even in those circumstances, using caching where possible is critical to increase the speed, stability, and scalability of your website.

Other considerations

Besides caching, you can help ready and maintain your cache, see Cache warming for useful information when preparing a website for launch or maintenance.

You must review your caching procedures and timing so your cache does not flush simultaneously causing a cache stampede resulting in serious performance issues with your website.

Important

Clearing all your caches at the same time has a high likelihood of causing your website to go down. Do not clear all caches simultaneously unless you have no other option.

The following links may be useful for formulating strategies to avoid cache stampedes:

Acquia Support can provide advisory services to help you assess your website’s caching strategy, and ensure your website is set up for an appropriate balance of fresh content and load speed.