Websites & hosting · Term

Caching

Caching is the practice of storing a ready-made copy of data, such as a web page, image or database result, so that later requests can be answered from that copy instead of being fetched or built again from scratch.

Caching trades freshness for speed. A cached copy is fast but may be out of date, so every cache needs rules for how long a copy stays valid and how it is cleared. Most "I changed it but the site still shows the old version" problems are caches doing their job a little too well.

Caching happens in several places at once: in the visitor's browser, on a CDN, on the web server and inside the application. Each layer is separate, which is why clearing one does not always make a change appear. When you are unsure which layer holds an old copy, a private browser window rules out your own browser first.

How it works

Browser caching is controlled by headers the server sends with each file. A Cache-Control header tells the browser how long it may reuse, say, a logo or stylesheet without asking again. Long lifetimes suit files that rarely change; when they do change, sites rename the file or add a version number to its address so browsers fetch the new one.

Page caching stores the finished HTML of a page. On a dynamic website, the first visitor triggers the full build with code and database queries, and the result is saved; later visitors receive the saved copy until it expires or the content changes. Pages that differ per visitor, such as baskets, account pages and checkout, must be excluded. Object caching keeps the results of frequent database queries in memory, often with tools such as Redis or Memcached, and PHP's own opcode cache keeps compiled code in memory so scripts do not have to be compiled again on every request.

A CDN cache keeps copies on servers around the world, following either the site's headers or its own rules. Invalidation, clearing copies when content changes, ties the layers together: a well-configured CMS or host purges the affected pages automatically when you publish.

Example

A florist updates its Valentine's Day prices, but the shop page still shows the old ones. The page cache on the host had been cleared, but the CDN still held its copy, and the owner's browser held another. Purging the CDN for that page and doing a hard refresh shows the new prices. The developer then configures the shop so that publishing a product change purges both caches automatically.

On the same site, product images get a cache lifetime of a year, with the file name changing whenever an image is replaced, while the basket and checkout are excluded from every cache so no customer ever sees another's order.

Why it matters for your business

Caching is usually the cheapest and largest speed improvement available, especially for dynamic sites, and faster pages mean better page speed scores and fewer visitors giving up. It also lets modest hosting handle traffic spikes. The risks are stale content and, worse, cached personal data shown to the wrong visitor. Set it up deliberately, know which layers exist on your site and make sure publishing clears what it should. On a small brochure site, the host's defaults are often enough; on a shop or membership site, caching rules deserve a proper review by whoever built it.

Common mistakes

  • Caching pages with personal content, such as baskets, accounts or logged-in views.
  • Stacking several caching plugins and a CDN with conflicting rules nobody understands.
  • Setting long browser cache lifetimes on files that are updated without changing their names.
  • Turning caching off entirely to avoid stale pages, instead of configuring purging properly.

Questions people ask

How do I clear my website's cache?

Clear each layer: the CMS or caching plugin, the host's server cache if it has one, and the CDN, usually from its dashboard. Then reload the page in your browser with a hard refresh or a private window. If one layer is missed, the old version may still appear.

Why does my website still show old content after an update?

One of the caches still has the old copy. It may be your browser, the site's page cache, a host-level cache or a CDN. Try a private window first; if the old version still appears, purge the site and CDN caches, then check again.

Does caching help SEO?

Indirectly. Caching makes pages load faster and keeps the site responsive under load, which supports better page speed and a smoother experience for visitors and crawlers. It does not change rankings by itself, and misconfigured caching can serve outdated or broken pages to search engines.

Related terms

Have something worth building right?