Cache state and origin counters
Measure whether the origin was contacted
Status 200 alone does not reveal whether the upstream generated a response. The lab backend increments a counter for every handled request and includes it in a small JSON body. Nginx exposes its cache decision in a separate response header. With an empty cache, sequential requests to the same eligible URL should first fetch a response and then reuse the same counter while it is fresh.
add_header X-Lab-Cache $upstream_cache_status always;Use this in the teaching lab, not as an unconditional production policy. MISS means no reusable stored entry was found; HIT means the cache supplied the response; BYPASS means the configured lookup exclusion applied; EXPIRED identifies an expired entry handled by fetching upstream. Other states are STALE (stale response used), UPDATING (stale response served while updating), and REVALIDATED (an expired entry validated upstream). Those advanced states require additional conditions and are not exercised here.
GET alpha.test/catalog?edition=basic -> MISS, counter 1GET alpha.test/catalog?edition=basic -> HIT, counter 1GET beta.test/catalog?edition=basic -> MISS, counter 2GET alpha.test/catalog?edition=plus -> MISS, counter 3Start from a fresh cache and no earlier backend requests to obtain these exact numbers. If another request reaches the origin, the counter can differ; compare equality for a hit and inequality for a new origin request. Status may be absent on routes with cache disabled. Do not equate every MISS with a successful cache write.
Run an isolation experiment
curl -sS -i -H "Host: alpha.test" "http://127.0.0.1:8080/catalog?edition=basic"curl -sS -i -H "Host: alpha.test" "http://127.0.0.1:8080/catalog?edition=basic"curl -sS -i -H "Host: alpha.test" -H "Cookie: demo=synthetic" "http://127.0.0.1:8080/catalog?edition=basic"The third response must be fetched from the origin. Repeating the anonymous request immediately should return the original anonymous counter, not the new bypassed counter. Test the other host and edition, and request the language-variant endpoint with two Accept-Language values. Its Vary header separates variants even though the lab key does not contain language.
curl -sS -i -H "Host: alpha.test" http://127.0.0.1:8080/shortsleep 4curl -sS -i -H "Host: alpha.test" http://127.0.0.1:8080/shortThe origin sets max-age=2 on /short. In an uninterrupted sequential test the second request should fetch a new response after expiry. No stale serving or revalidation is enabled. If eviction or restart occurred, a MISS is possible instead; inspect the origin counter and logs rather than asserting the state alone.
Practice and next steps
Use the matrix in lab-fixtures/chapter-25 to verify public reuse and isolation, then explain any unexpected cache state before changing configuration. Offline fixture tests verify the origin logic only. Next: advanced caching, CDN and content acceleration.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Cache state and origin counters
Interpret cache status and origin counters to verify reuse, expiry and isolation in a bounded local lab.
Two sequential eligible requests return MISS and HIT with equal counters. What does this suggest?
What does BYPASS show?
A fresh key is requested for another host. What is expected?
Which status indicates validation of an expired entry?
What does a passed offline backend test establish?