Skip to content
explainroo

How a cache makes a website faster

A cache keeps a copy of a page the server already built, so the next visitor gets it right away. When the data changes, that copy has to be replaced.

Transcript

Many websites build each page when someone asks for it. A cache keeps a copy, so the next visitor gets the page faster.

Say a visitor opens a product page in an online shop. The server gets the name, the price and the description from the database. Then it builds the page, and that takes time.

It sends the page back, and it keeps a copy in the cache.

When a second visitor asks for the same page, the server sends the copy right away. It skips the database and the building.

Later, the shop lowers the price. The cached copy still shows the old price, so visitors see stale content. When data changes, the old copy has to be thrown away or replaced.

Web pages get cached in several places. The browser keeps copies on the visitor’s device. A content delivery network, or CDN, keeps copies on servers near the visitor. And the web server keeps its own copies.

So a cache sends a saved copy instead of doing the slow work again, until the data changes.

More from technology