Review the prerequisites
Suitable for: Backend developers learning Agent applications.
- Semantic and authorization equivalence for cache reuse
- The prerequisite for a cache hit is that the new request and the old result are still equivalent in terms of task semantics, data version, and authorization scope. Neither similar text nor short-term expiration can be independently proven to be safe for reuse.
How does the mechanism work?
Step-by-step explanation
- Is it enough to just put user_id into the key?
The main question designs cache keys; explain why a user identifier alone is insufficient.
- What should I do if the permissions have changed but the cache has not expired?
Cache versioning must also handle uncertainty in revocation propagation.
- How to verify when semantic cache encounters "contains" and "does not contain"?
Semantic matching can miss decisive conditions, so provide concrete checks.
Debugging · Diagnose failures
Diagnose failures · Semantic and authorization equivalence for cache reuse
Objectives of this level: Find the first incorrect decision in a cache leak using paired inputs and a source repair.
Visual guide · A hit needs current equivalence
A fresh TTL is only one test. Current authority comes first; write receipts require reconciliation rather than read-cache reuse. Select the figure to open it at full size.
Known faulty implementation
A helper that returns hit whenever expires>now omits current authorization, completeness and version binding. A second helper checks tenant/order/query but omits user from the entry key; it can reuse another user’s result under the same tenant. Neither fault is fixed by reducing TTL.
Same-input diagnosis
Use the foundation payload, then change principal.active=false without changing entry. Expected denied/revoked, faulty hit. Restore active and change entry.user=u2: expected miss/key_mismatch. Restore user and change request.policy=4: expected miss/version_mismatch. Record first wrong branch, expected/actual and input hash.
Repair and distinguish
Place identity/active/ownership checks before cache reuse; include user in the entry binding. Show the actual source diff, the original failure, both repaired reports and a new u3 entry. Keep input unchanged. The 20-case run is regression evidence; the added unseen-to-the-author condition and reviewer observation belong in a separate assessment record.
python3 lab_runner.py scaffold --course agent-cache-correctness --out cache_student.py
python3 lab_runner.py grade --course agent-cache-correctness --module cache_student.py --out cache-report.json
code example
One-field counterexamples
Change only entry.user from u1 to u2. A key missing user incorrectly hits; expected miss/key_mismatch. Restore user and change request.policy to 4; expected miss/version_mismatch. Show the different first failing branches.
Acceptance task for this level
Reproduce a TTL-only or user-omitting key bug, distinguish it from stale data, patch its source and rerun the same cases plus a new user variant.
Reading this browser’s record…
Hide the answer and check your understanding
Both revoked and old-policy cases fail. How do you avoid treating them as one TTL problem?
Expand reference derivation
Hold now/expiry constant. Revocation must fail before entry access; a policy change must miss after current authorization. Different first failing branches imply different fixes.
Further explanations and practice
When encountering unfamiliar principles, first read the implementation, continuous questioning and migration cases, and then independently explain the premise and boundaries. Answers and notes are saved to the original account record.
All linked explanations and exercises (1 )
Sources and verification scope
The principles are based on public information; the numbers, cases and tasks are the teaching design of this website. Offline experiments verify the range noted on this page, and the learning effect still needs to be judged through independent tasks and feedback.
- OWASP: Data isolation and security boundaries in RAG
- Anthropic:Effective context engineering
- MCP 2025-11-25:Authorization
- OpenAI: Reusing prefix computation with prompt caching
- Extended practice runner
- Cache contract cases
- Extended practice source package
- OWASP authorization
- HTTP caching RFC 9111
- Integrated project guide
- Role-specific delivery examples
- Independent integration assignment
- Author-designed assessment examples
- Project integration source ZIP