What is caching? Browser, page and object caches

Caching keeps a ready-made copy of something so it does not have to be built again. The layers that make websites fast, and when each one helps.

1–2 minutes
Cooling equipment on the roof of a data center

A cache is a stored copy of something that was expensive to produce, kept so the next request can be answered instantly. Websites use several layers of cache, each saving a different kind of work.

LayerStoresSaves
Browser cacheImages, styles and scripts on the visitor’s deviceDownloading files again
CDNCopies of files or pages near the visitorDistance and load on your server
Page cacheFinished HTML pages on your serverRunning PHP and database queries
Object cacheResults of database queries, in memoryRepeating the same query
Opcode cacheCompiled PHP codeRe-reading and compiling PHP files

Browser cache

Your server tells browsers how long to keep files with headers like Cache-Control: max-age=2592000 (30 days). Repeat visitors then load your images and styles from their own disk. Change a file’s name or add a version, such as style.css?ver=2, when you update it, so browsers fetch the new one.

Page cache

The biggest win for most sites. The first visitor to a page triggers the full work; the result is saved as a static file, and later visitors get that file. On WordPress this is done by a caching plugin or by the web server (for example Nginx’s FastCGI cache). See how much RAM a site needs for why this matters.

Object cache

A store in memory, such as Redis or Memcached, that keeps the results of database queries. It helps pages that cannot be fully cached, like shop carts and account pages.

Opcode cache

PHP’s OPcache keeps compiled code in memory. It is built into PHP and should always be on.

When caching causes problems

  • You see an old version after an edit: clear the page cache or the CDN.
  • One visitor sees another’s data: a page meant for logged-in users was cached. Never page-cache carts, checkouts or account pages.
  • Changes do not show for everyone: different layers expire at different times. Clear from the top down: page cache, then CDN, then browser.

Something out of date? Software changes. If a step no longer works, tell us and we will check it and update the page.