Arezgitfield notes / engineering
Engineering practiceUPDATED OCT 9, 2026

Use ETags Without Caching the Wrong Response

Define representation-aware ETags, choose private and shared cache policies, and verify conditional requests without weakening authorization.

Arezgit Editorial5 min read
AREZGIT / FIELD NOTEENGINEERING PRACTICE
An ETag can save response transfer while still returning the wrong result if the cache ignores language, permissions, or account scope. Before adding conditional requests, define which repre
READ / VERIFY / APPLYTECHNICALLY REVIEWED

An ETag can save response transfer while still returning the wrong result if the cache ignores language, permissions, or account scope. Before adding conditional requests, define which representation the validator identifies and who is permitted to reuse a stored response.

This guide covers HTTP response validators and cache policy for application endpoints. The header examples are synthetic. The design must be verified through the actual browser, reverse proxy, and CDN because each introduces another place where a response may be stored or reused.

Identify the representation rather than only the database row

One record can produce several representations: localized text, a summary view, an administrator view, and a redacted user view. A validator based only on the record's update timestamp may remain unchanged while the response changes because permissions or serialization rules changed.

The HTTP semantics specification defines entity tags as validators for selected representations. Use that scope when designing the tag. A strong tag requires the corresponding representation identity; a weak tag expresses a less exact equivalence and is not a substitute for a strong write precondition.

Choose inputs that change whenever the relevant response changes. That may include a representation version and the source data version, or a digest of the final bytes. Account for content encoding and any proxy transformation when claiming byte identity. Avoid a design that hashes one serialization but sends another.

Do not include raw confidential values in the tag. A validator is response metadata that can appear in logs and client storage. Give it no meaning as a permission grant, and define when representation-version changes invalidate old tags.

Choose a storage policy separately from validation

For a synthetic account-specific summary that may be stored privately but should be checked before reuse, the response policy could include:

Cache-Control: private, no-cache
ETag: "summary-v3-example"

The HTTP caching specification distinguishes validation from storage. no-cache requires validation before reuse; it does not mean that nothing is stored. no-store prohibits caching, while private prevents storage by shared caches under the directive's normal unqualified meaning.

Choose based on the information and user experience. A public, immutable asset can have a different policy from a changing account dashboard. A sensitive response may need no-store rather than a private revalidation policy. Do not apply one global cache setting simply because all routes return JSON.

If response selection depends on a request header, configure the cache's representation key and appropriate Vary behavior. Avoid relying on a validator to compensate for an incorrect cache key. Separate users must not share a stored response merely because the underlying record has the same update time.

Evaluate conditional reads after identity and authorization

In a synthetic read flow, the server authenticates the caller, authorizes access, selects the current representation, and compares the supplied If-None-Match value. If it matches for a GET request, a 304 response allows the client to reuse its existing representation without a new response body.

Keep the current validator and relevant cache metadata consistent on that response. A client needs to update its stored metadata correctly, not infer policy from the absence of a body. Treat lists of validators and the wildcard form according to the protocol instead of comparing only an arbitrary substring.

Never return 304 before checking access. In a synthetic failure case, a user loses permission after caching a report. A matching validator should not bypass the new permission decision. The server must evaluate the current request's authority even when it expects to avoid sending the representation.

Bound conditional-header parsing and use the framework's maintained HTTP handling where possible. Return a stable error for rejected input without exposing internal parser or application details. An optimization should not create a second, weaker path around the endpoint's ordinary validation.

Keep write concurrency distinct from read caching

An application may also use If-Match to reject an update based on an outdated representation. That solves a different problem: preventing one accepted write from silently overwriting another. Read cache hits do not establish that a later write is still current.

Use a strong validator when the write contract requires exact comparison. Make the authoritative comparison and mutation atomic, such as through a conditional database update tied to the current version. Checking a value in application memory and then performing an unconditional write leaves a race between the two steps.

When the condition fails, return the documented conflict outcome and give the client a recovery path. The interface can refresh current data and let the user reconcile changes. Automatically retrying the same overwrite with a fresh validator would defeat the reason for the precondition.

Idempotency is another separate property. A conditional write can still have retry ambiguity after a network failure. The guide to idempotent API operations explains how to handle repeated requests without confusing that guarantee with optimistic concurrency.

Test the entire cache path

Verify an initial response, a matching conditional request, a changed representation, and an expired cache entry. Then vary language, account, role, query parameters, and content encoding wherever those inputs affect the output. Assert both response bodies and cache metadata.

Include permission revocation, sign-out followed by another account signing in, and a shared-cache configuration that would expose an incorrect key. Test the deployed proxy path rather than only calling the application handler. Browser developer tools and controlled integration tests can reveal which layer served each response.

Measure response sizes, validation frequency, and latency with representative requests before deciding that caching improved the endpoint. A validator may reduce transferred bytes while leaving expensive representation generation unchanged. Choose the policy that preserves the access contract, then optimize the work the evidence identifies.

READER SIGNAL

Was this guide useful?

Your rating helps us prioritize clearer, more practical technical content.

AREZGIT / DESKTOP WORKSPACEFROM FIELD NOTE TO RELEASE

Review diffs, run checks, and prepare the release in Arezgit.

Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.

Explore Arezgit