HTTP cache and application cache: who refreshes the page?
Separate browser, shared HTTP, and application caches, and explain an old body behind a 304 response.
An editor changes a title, yet a reader still sees the previous text. Reloading returns 304 and the network panel looks uneventful. That does not yet answer whether the change reached the page. A browser, a shared HTTP cache in front of the application, and an application cache inside it may operate independently along the reading path. Each reuses its own result and has its own reason to refresh it.
Consider one synthetic public resource. The exercise aims to find the layer retaining the previous representation and explain its decision using bytes and headers. We executed the local model on PHP 8.5.12 with controlled logical time. These are actual PHP observations, without network requests, a real browser, a CDN, or Symfony HttpCache.
Three owners of reuse
The browser HTTP cache stores a response for the client. A shared cache serves many clients and may finish a request before the application is contacted. An application read cache stores selected data or a prepared result. It can return an old card even when the HTTP request has already reached the origin.
It helps to write three separate questions. May the client reuse the response without a request? May the intermediary respond without the origin? Did the origin itself read the current source? A successful check at one level does not answer for the others. Changing a database row does not automatically remove every derived copy, and purging the intermediary does not clear application storage.
Earlier articles about a domain and Cloudflare checked the path to a protected lab. This exercise involves no DNS, ingress, or access configuration. It also does not repeat the transaction scenario for delivering invalidation or the choice of a domain stale policy. Its new subject is how already selected application bytes interact with HTTP freshness.
What freshness means
The exercise response has this contract:
Cache-Control: public, max-age=10, s-maxage=30
ETag: "representation-hash"
max-age supplies the interval for a private HTTP cache; s-maxage supplies a separate interval for a shared cache. Freshness depends on response age, rather than the last database change. Our model uses a strict inequality: current_age < lifetime; at the exact boundary, the response already needs validation. RFC 9111, section 4.2 describes the general rule and age calculation.
The application snapshot separately lives for 60 seconds from obtaining the source. These numbers are chosen only to make the exercise readable. They are not recommended lifetimes for a journal. One policy does not follow from the other: a short browser lifetime does not force the origin to reread the database every ten seconds.
An ETag belongs to selected bytes
The origin first selects a representation and then calculates a validator for that representation. In the exercise, the body is uk:A or en:A; the hash covers locale and text. Real HTML may also depend on a template, a variant, or an encoding. If these differences change the representation, its identity needs appropriate handling too.
Do not attach a fresh database revision as the ETag of old application bytes. The header and body would describe different states. Hashing after selection in the teaching code is deliberately simple: it demonstrates the correct correspondence without promising CPU savings during validation.
For a conditional GET, the client sends If-None-Match. A match against the selected representation's validator permits a 304 response without content; the client uses stored bytes. This is the semantics of RFC 9110, sections 13.1.2 and 15.4.5. In Symfony, Response::isNotModified() performs the relevant check. It does not invalidate the application cache.
The sequence observed in the model
The initial source A becomes B at logical second 5. Each scenario starts with empty stores. Transport time is zero; background refresh and permitted stale serving are absent. The locale is in the path, with no Accept-Language negotiation.
| Second | Request path and status in the model | Client bytes |
|---|---|---|
| 0 | Unconditional GET, origin 200 | A |
| 11 | Conditional GET, fresh shared cache returns 304 | Stored A |
| 31 | Shared cache validates with origin; origin selects application A and returns 304 | Stored A |
| 61 | Shared cache is stale; application snapshot has also expired; origin 200 | B |
At second 11, the browser copy already needs validation, but the shared copy is still fresh. The intermediary can compare the ETag itself and return 304 without calling the origin. The report must record both the wire status and the bytes reused by the client. An absent 304 body does not mean an empty page.
At second 31, the request reaches the origin. Application storage still retains A, so the validator matches. In the frozen model, successful validation updates Date to second 31 and shared Age becomes zero. That renews the age of an HTTP response; it does not obtain B from the source. Distinguish these events even when they share the 304 status.
At second 61, exactly 30 seconds have passed since the last validation. This is the s-maxage boundary, so the shared cache contacts the origin again. The application's 60 seconds have also elapsed: it now selects B, a new ETag, and 200. Observed origin counters at the four observations are 1, 1, 2, 3; source reads are 1, 1, 1, 2.
Why one purge is insufficient
The first additional scenario clears only the application cache after changing A to B. At second 11, the fresh shared cache still responds for A. The origin counter is unchanged. New readiness inside the application does not tell external stores to abandon their result immediately.
The second scenario clears only the shared cache. The next request reaches the origin, but it selects application A again. The cause at the other level is now visible as an increased origin counter without a new source read. These negative controls are more useful than clearing everything at random: they test a specific hypothesis about who owns the old result.
A real fix needs a coordinated refresh contract across dependent layers. That may use invalidation, a bounded lifetime, or another explicitly accepted policy. HTTP refresh itself does not replace delivery of a database change, and this exercise adds no universal mechanism for purging every CDN.
The private resource boundary
A separate negative resource returns private, no-store. The model retains it in neither shared nor client storage. Each read contacts the source again. This checks the storage prohibition under the selected contract; there is no complete authentication model here.
Do not use no-cache as a synonym for a storage prohibition: it concerns validation before reuse. RFC 9111, section 5.2 defines these directives. Existing protected application routes keep their own policy; a synthetic public resource is no reason to weaken it.
Age does not start with every client request
After a 304 from a fresh intermediary, the client may reuse its body, but this is not new source validation. In the model, Age at second 11 is 11. If the client simply reset its own age after every such response, it could extend freshness beyond the interval allowed by the origin. We therefore retain origin validation time separately from the time of the client request.
This distinction helps interpret diagnostics: a young local entry may still contain a response with substantial inherited age. Date alone, without Age, also does not explain the complete path. A real network additionally requires transmission time and the age calculation rules. Zero delay removes these variables from the model only to test the particular sequence; it does not define network behavior.
Also freeze the client request type. Here it is an ordinary conditional GET after local freshness ends. A forced reload, disabling cache in developer tools, or a special request Cache-Control changes the assumptions. Test those in separate scenarios with their own expectations. Combining these modes accidentally can make apparently similar checks incomparable even when server code and data have not changed.
Actual local results
The additive code develops one teaching Symfony application: a command builds Responses with HttpFoundation, while local objects model the client and shared cache. This is a deliberately limited model, not execution of a real browser, Symfony HttpCache, or Cloudflare. It provides controlled seconds without waiting and separate counters at each boundary.
We retained request conditions, wire status, ETag, Date, Age, Cache-Control, selected-body hashes, and counters. At 0/11/31/61, statuses were 200/304/304/200 and representations were A/A/A/B. Origin call counts were 1/1/2/3; source read counts were 1/1/1/2. At 31, Date renewed to logical second 31 and Age became 0; at 61, the previous shared age equals 30, the expiry boundary. Neither 304 carried a new body. Separate tests checked matching and nonmatching validators, UK/EN, both purges, and private/no-store without a retained shared copy. The command and container lint exited with code 0. Versions: Symfony 8.1, PHP 8.5.12, PHPUnit 13.4.6; the PHP minimum for the canonical application with its suite is 8.4.1. Other PHP versions were not run.
To interpret the result, retain two identities together: the current source revision and the selected application result revision. At second 31 they deliberately differ. This shows that HTTP validation behaved consistently with selected bytes while the business expectation of an update remains unmet. A practical interface need not show these internal details to the reader. They belong in an authorized diagnostic trace so the next fix has a concrete check instead of relying only on the impression created by reloading a page.
A separate regression protects controlled time: read and origin reject backward movement before changing storage or counters; equal logical time is allowed. This prevents an invalid scenario from artificially making a stored response younger. After the correction, 8 PHPUnit tests with 47 assertions passed. The main command retained identical stdout; this is a local model rather than a new network measurement.
When investigating a real page, begin with one controlled article and one authorized client. Record the source revision, compare authorized direct origin reading with the response through an intermediary, and establish who generated the validator. Change one condition at a time. Once the bytes, age, and owner of each decision are visible, “the page did not update” becomes a cause that can be tested.