At 10:00 on a Monday, the owner of a small online sweets business in Lucknow lowers the price of a Diwali gift box from ₹1,299 to ₹999. The admin panel confirms it. At 10:05 she opens the product page on her phone and sees ₹1,299. She refreshes: ₹1,299. A colleague on the office laptop sees ₹999. Customer support, meanwhile, gets a message from someone who was charged ₹999 after seeing ₹1,299 on the page. Four people, three experiences, one price. Nothing is “broken” in the usual sense. This is a cache doing exactly what it was told.

We will use this story to walk through where stale data lives, because testing a system that caches is mostly a matter of knowing how many places can hold a copy.

Where the old price was hiding

A request for that product page can pass through several layers, and any of them may answer from memory instead of asking the layer behind it.

  • The browser cache on the user’s device. The server sends a Cache-Control header, such as one allowing reuse for an hour, and the browser obeys.
  • A CDN (content delivery network) or reverse proxy in front of the site, keeping copies near users so fewer requests reach the origin server.
  • An application cache, often an in-memory store such as Redis, holding query results or rendered fragments.
  • The database itself, with its own buffers, and any read replica that lags slightly behind the primary.

In Lucknow, the owner’s phone had cached the page for an hour, while the office laptop had not visited it before and so fetched a fresh copy from the CDN, which had been told to purge on change. The checkout, reading the price from the database directly, charged the new price. Three layers, three timestamps.

The vocabulary that decides behaviour

You need only a few terms. TTL (time to live) is how long a copy may be served before it must be refreshed. max-age in Cache-Control gives that lifetime in seconds. no-store tells caches not to keep the response at all, which is what you want for pages with account details. no-cache, despite the name, allows storing but demands revalidation with the server before reuse.

Revalidation works through validators. The server sends an ETag, a version fingerprint of the response. Next time, the browser asks “do you still have version X?” If so, the server answers 304 Not Modified, with no body, saving bandwidth while still guaranteeing freshness. Seeing a 304 in the network panel is a healthy sign, not an error.

Then there is invalidation: removing or replacing a cached copy before its TTL ends, when the underlying data changes. A well-worn line in computing says it is one of the hard problems, and the Lucknow story shows why. Someone must remember every cached copy of that price, in every layer, and tell each of them.

How to test it

The most useful test is a plain sequence: change the data, then observe it from every layer and from a user who has already seen the old value. Reload with the browser’s normal refresh and note the result. Then do a hard reload, and compare. If they differ, a copy is being held somewhere. Open the network panel and read the response headers on the request: Cache-Control, ETag, and, where a CDN is present, headers such as Age that report how old the served copy is (the exact headers vary by provider, so ask what yours adds).

Beyond that sequence, test these specifically:

  • Time-based expiry. Ask for a short TTL in the test environment so you can see an entry expire, rather than waiting an hour.
  • Invalidation on change. Update a price, a stock count, a banner. Confirm each cached view updates within the agreed window, and write that window down. “Within five minutes” is a testable requirement; “quickly” is not.
  • Static file updates. After a release, do users still run the old script or stylesheet? Teams often solve this by putting a content hash in the file name so a changed file gets a new address, called cache busting. Verify the new build is actually picked up.
  • Critical paths read fresh data. Checkout, payment amount, stock reservation and balance displays should not trust a stale copy, even if browsing pages do.

The dangerous kind of stale

An old price is annoying. A cached personal page is a breach. If a shared cache, such as a CDN, stores a response that was meant for one logged-in user and serves it to the next visitor on the same URL, the second person sees the first person’s name, address or order history. It comes from missing or wrong cache headers on personalised pages, or a cache key that ignores the user. Test it by logging in as user A, loading an account page, then requesting the same URL as user B (or as a logged-out visitor) through the real CDN path, and confirm that no A data appears. Also check that authenticated responses carry restrictive caching headers.

Why your test environment lies

Many QA environments have no CDN and a tiny or disabled application cache, since it makes testing simpler. The result is a clean pass in QA and the Lucknow experience in production. If caching is a feature of the real system, it must be present, with realistic configuration, somewhere you can test, even if only a pre-production stage. Otherwise you are certifying a system that does not exist.

Be modest about what a tester can see. You can observe stale behaviour and headers; you may not be able to see the internal cache keys or the purge mechanism, and a developer or platform engineer will have to confirm them. And some staleness is a deliberate trade-off, for instance an eventually consistent product count accepted by the business. The testing question is not “is it ever stale?” but “is it stale for longer than we agreed, and in places where staleness does harm?”

Figures and names in the examples are illustrative.

Leave a Reply

Trending