Skip to content
← Free FDE training guides

Free learning / 45-minute caching lab + 25-minute publication proof

Caching 101: when can you reuse earlier work?

Understand hits, expiry and invalidation, then reproduce a late publisher overwriting newer work. Check the authoritative source even after a cache entry disappears.

No account needed. Use your own copy for writing and keep the original as a reference.

Engineering lab library / Run locally

See when a saved result stops being reusable.

Predict eight requests, then remove the source-version and permission checks in separate copies. Compare avoided work with stale and unauthorized results.

Real in-memory SQLite with fictional sources and permission rows. No model, credentials, network or file writes. Logical time and render counts explain behavior; they do not measure latency.

Search titles, outcomes and prerequisites, then narrow by runtime.

2 of 2 labs · All labs

  1. Start here / Python 3.11+ · Standard library

    Caching 101 · local SQLite lab

    Distinguish safe reuse, changed sources, workspace scope, revoked access, unavailable evidence and expiry.

    Python 3.11+ · Standard library · No model or network

  2. Python 3.11+ · Standard library

    Late cache publication · process proof

    Pause an old publisher, commit a newer source and compare atomic publication with a cache-row-only check after deletion.

    Python 3.11+ · Temporary SQLite file · Owned child process · No network

An operator opens the same guide twice. Rebuilding its excerpt every time feels wasteful. Saving the first result seems obvious—until the guide changes or the operator loses access. How does the application know when reuse is still valid?

This original 45-minute workshop starts with that question. You will predict eight decisions, inspect real local SQLite rows and create two separate defects in disposable copies. All organizations, documents and text are fictional. Python 3.11 or later is sufficient: no packages, model, credentials, network or cloud account. The baseline program uses an in-memory database and writes no files. The optional publication lab in section 7 uses a temporary SQLite file and an owned child process.

1. Name the object and the technique

A cache stores a copy of data or earlier work for reuse. Caching is a technique, not a model or programming language. A hit finds an eligible entry; a miss requires the application to fetch or compute the result again.

If you know build systems, compare a saved excerpt with a compiled artifact. When an input changes, a dependent output can become obsolete. The analogy has a limit: access to AI context can also change independently of its content. A content hash cannot tell you whether a person may read the copy now.

TermPlain meaningQuestion to ask
Cache keyIdentifier used to find a saved entryCould two requests share this key but require different results?
Source of truthAuthoritative value or permission recordWhere can I establish what is current?
Time to live (TTL)Allowed entry lifetimeWhen does age alone force a miss?
InvalidationMaking an earlier entry unusableWhich source, permission or configuration change triggers it?
EvictionRemoving entries to reclaim capacityCan the application still work correctly after removal?

Before choosing a cache product, name the object. Here it is a formatted source excerpt. It is neither an answer generated by an AI model nor proof that the excerpt is sufficient to answer a person's question.

2. Follow the dependencies before the saved copy

The fictional operator has access to both North and South. Both workspaces have a document called guide-7, but their text differs. The lab's cache key includes the active tenant, principal, document and renderer version. Each entry also records its source revision and expiry.

The baseline checks current permission and source metadata on every request. Only then does it look for a matching entry. A missing, obsolete or expired entry triggers an actual local render and database write. Permission loss withholds the result and deletes that caller's entry. Missing current evidence withholds without reading the saved body.

The rendering function only formats a string with its source reference. This makes the mechanism inspectable without a model. A hit skips that function; it does not skip the current metadata lookup or establish an end-to-end speedup.

UNDERSTAND THE SYSTEM

Can we reuse this earlier result?

Follow eight requests from the original local SQLite exercise. Reuse, rebuilding and withholding are different decisions. The supplied clock makes each transition inspectable; this is a replay of retained results, not a running cache or a speed benchmark.

FOLLOW THE WORK

Watch one example, step by step.

8 authored stepsYou control the pace
01 / EXPLORE THE PARTSControls loading · written explanations below
Direction of information or workReturn / feedback

WHAT THIS PART DOES

Current request

Trusted application context identifies the active workspace and caller. Neither model text nor a cache entry establishes that identity.

CONNECTED TO
  • Identify caller: Reuse checks
Read the full worked example
  1. 01
    First request: obtain the current excerpt

    North has permission and guide-7 is version 1. There is no saved entry. Assemble it, record its version and expiry, and return it. This is a cold miss.

    COLD: miss-empty · one render

  2. 02
    Repeat request: reuse the same work

    At logical second 1, current access and version still match and the entry is younger than its five-second lifetime. Reuse it without rendering again. Metadata checks still cost work. This hit does not extend expiry: it remains second 5.

    WARM: hit · zero new renders

  3. 03
    Another workspace: a different entry

    The same fictional operator can enter South. Its guide has the same document ID but different text. The tenant field keeps North's copy out of South's lookup; a current access check is still required.

    OTHER TENANT: miss-empty · South owns its own excerpt

  4. 04
    Changed source: young does not mean current

    At second 3, North's guide becomes version 2. The old entry has not expired, but its source dependency changed. Rebuild from version 2. The broken version-check experiment instead returns the old blue excerpt.

    SOURCE CHANGED: miss-source-changed · new version returned

  5. 05
    Revoked access: a hit must not escape

    At second 4, North's permission row is removed. Withhold the excerpt and remove that caller's entry. The earlier successful request and remaining lifetime cannot authorize this one.

    PERMISSION REVOKED: withheld · cache not read

  6. 06
    Restored access: build a new entry

    At second 5 the grant is restored. The revoked caller's old entry was deleted, so this request finds no candidate. It renders current version 2 and stores a new expiry of 10. Restored permission alone does not resurrect the old row.

    ACCESS RESTORED: miss-empty · v2 stored · expires 10

  7. 07
    Unknown evidence: stop before lookup

    At second 6 an injected failure flag makes current evidence unavailable. The previous request saved an entry, but this request neither reads nor deletes it. No metadata check or cache-body lookup completes. Withholding is different from an observed cache miss; earlier permission cannot fill the gap.

    EVIDENCE UNAVAILABLE: withheld · no lookup · no deletion

  8. 08
    Exact expiry: rebuild after current checks

    At second 10 current evidence is available again and access is allowed. The stored entry expires at 10, so now >= expires forces a miss even though its source revision still matches. Rebuild version 2 and store expiry 15. This lab enforces age when reading; it does not run a background purge.

    EXPIRED: now 10 = expires 10 · rebuild · expires 15

Read the connections in plain English
  1. 01
    Current request → Reuse checks

    Use trusted context to establish the active workspace and principal.

  2. 02
    Current source → Reuse checks

    Look up current version and permission before trusting a saved copy.

  3. 03
    Reuse checks → Saved excerpt

    Locate an entry only after current access is established.

  4. 04
    Reuse checks → Assemble excerpt

    Missing, expired or obsolete entries require current source work.

  5. 05
    Assemble excerpt → Returned result

    Store the assembled excerpt and its dependencies, then return it.

  6. 06
    Saved excerpt → Returned result

    An eligible entry avoids rendering; authority checks still ran.

  7. 07
    Current source → Assemble excerpt

    On a miss, read the source body from the active workspace before assembling a replacement.

  8. 08
    Assemble excerpt → Saved excerpt

    Write the newly assembled excerpt, its source revision and expiry for a later request.

Check your understanding: The entry has four seconds left. Is it safe after permission changes?

No. Its age does not establish current authority. Check permission for this request and withhold on denial. Shortening TTL reduces an age window; it does not replace the access check.

3. Predict and run eight requests

First open Caching 101 and choose Try it. The visual replay uses recordings of this program, including both deliberately broken copies below. Each request shows the current evidence and the cache row actually read or stored. Choosing a case replays its place in the sequence; it does not execute Python in your browser.

Download fde-caching-lab.py into a new folder. Predict the result for every row below before running it:

Code example
python3 --version
python3 fde-caching-lab.py
CaseLogical secondChange to inspect
cold0North asks for guide-7 with no saved entry
warm1Same workspace, caller, guide and current revision
other-tenant2Same operator selects South and its guide-7
source-changed3North's guide changes from blue version 1 to green version 2
permission-revoked4North's grant is removed while the entry is young
access-restored5North's grant is restored; make a fresh request
evidence-unavailable6Current evidence cannot be obtained despite the saved entry
expired10Current evidence is available; the entry reaches its age limit

These are supplied logical seconds, not measured runtime or sleeps. The five-second TTL uses an inclusive expiry boundary: now >= expires is expired. The deadline is fixed when the entry is written. A warm hit does not extend it. Expiry makes a row ineligible when read; it does not physically remove every expired row in the background. South's row is still present at the end of this small exercise. A real cache product may implement different expiry and cleanup behavior, so read its contract separately. The unavailable-evidence case uses an explicit failure flag; it does not take a database or cloud service offline. The restoration request is deliberately visible. Without it, the previous revocation would leave no warm entry for the unavailable-evidence case.

Inspect cache, decision, body, current_version, returned_version and render_calls_this_request. Explain each observation in a sentence before checking the reasoning below. The stages list records the path taken. Inspect key, current_allowed, entry_at_lookup and entry_stored to compare the current checks with the actual SQLite row. cache_lookup_performed: false means the body was not looked up; a null entry alone would be ambiguous. The revocation case also records removed_entries: 1 without reading that body.

4. Compare the evidence and change one rule

The baseline produces:

  • cold: miss-empty, North version 1, one render.
  • warm: hit, North version 1, no render.
  • other-tenant: miss-empty, South's amber version 1, one render.
  • source-changed: miss-source-changed, North's green version 2, one render.
  • permission-revoked: withheld, no body and no cache read.
  • access-restored: miss-empty, North version 2, one render.
  • evidence-unavailable: withheld, no body and no cache read.
  • expired: miss-expired, North version 2, one render.

There are five renders, one warm hit and two withheld results. This is an operation count for one synthetic sequence. It is not a measured improvement in latency, token cost or learner performance.

Make two separate fresh copies of the original file:

  1. In the first copy change CHECK_SOURCE_VERSION = True to False. Run it. At source-changed, the entry is still young, so the broken copy returns blue version 1 even though current_version is 2. The stale result identifies the dependency that the check protected.
  2. In the other fresh copy change CHECK_CURRENT_ACCESS = True to False. Run it. At permission-revoked, the broken copy returns the warm green excerpt despite the removed grant. The key and TTL did not enforce authority.

Keep the baseline and both reports separately. Re-enable the check in each copy and confirm the corresponding defect disappears. These mutations demonstrate bugs in an isolated exercise; they are not configuration recommendations.

5. Separate application reuse from model caching

An application might cache a source excerpt or a completed answer. Reusing an answer additionally requires a contract for the task and its model, prompt, source and policy dependencies. Similar wording does not establish equivalent permission or an equivalent answer.

Claude's prompt caching can reuse processing of eligible repeated input prefixes. It does not turn a saved final answer into a current one. Use the provider's current eligibility and usage documentation when measuring that feature; this exercise implements no provider cache or token billing.

A transformer's key-value (KV) cache is a different inference mechanism for reusing attention-related state. Continue through the NVIDIA memory material for the model-runtime layer: GPU memory 101. Our SQLite excerpt cache does not model GPU memory.

Before optimizing any layer, identify the repeated work and what evidence would show a useful improvement. Include misses, validation and invalidation overhead in the comparison. A high hit count alone says nothing about answer quality.

6. Write a contract another engineer can challenge

Complete this template for one source cache in your proposed AI assistant:

Text example
Cached object:
Trusted caller and active workspace:
Key fields:
Authoritative source and permission dependencies:
Maximum age and expiry boundary:
Events that invalidate reuse:
Behavior when current evidence is missing:
Allowed result and refused result:
Work actually avoided; work still performed:
Concurrent update/revocation test still needed:
Receiving owner and rollback condition:

The local program uses one sequential process. It does not prove atomic revocation across concurrent workers, distributed cache coherence, durability, memory bounds or provider behavior. If many workers miss at once, they can duplicate expensive work; describe how you would test and bound that load. For sensitive data, decide whether a cache is appropriate before designing it.

Challenge a late writer

Start with this authored design scenario, separate from the sequential program. Section 7 executes its publication ordering with synthetic local data. Two workers assemble the same scoped excerpt:

OrderEventWhat can go wrong?
1Worker A reads source revision 1 and starts formattingIts input is now a snapshot
2The source changes to revision 2A's unfinished output may already be obsolete
3Worker B reads and stores revision 2The cache now holds the newer result
4A finishes and unconditionally replaces the entryRevision 1 can overwrite revision 2

Deleting an old cache row when the source changes does not prevent a worker from publishing old work afterward. Propose a version-aware publication rule, or immutable keys per revision with authoritative selection of the current revision. Explain how the source body and its version are read coherently, and what happens if the source changes between the check and return. A version label attached to the wrong body is not useful provenance. Specify and test the consistency boundary your application actually promises.

Now consider many workers missing simultaneously: a cache stampede duplicates the work you hoped to avoid. Request coalescing lets one worker produce the result while others wait. Bound the wait, define producer-failure behavior, and recheck each waiting caller's current authority before disclosure. Coalescing is a performance technique; it does not establish source freshness or make revocation atomic. A lock by itself is not the complete reuse contract.

Keep three acceptance experiments separate:

  • Freshness: pause A, publish B's newer result, resume A, and inspect the stored and returned revision and body.
  • Authority: revoke access while a request waits, then inspect whether any body is disclosed under the stated revocation policy.
  • Load: make bounded concurrent misses and measure duplicate work, waiting, failures and full-request latency against an uncached baseline.

The baseline does not execute these tests. The optional companion below executes only the freshness/publication ordering in one local SQLite database. Authority, load, distributed consistency and suitability for sensitive data remain separate receiving questions.

Explain the baseline to another engineer without reading the code: what was cached, what changed, what was returned, and why? Then let them choose one dependency you missed. That discussion is the handoff artifact.

7. Run the late-publication proof lab

Optional 25 minutes · Python 3.11+ · Standard library. Download the cache publication companion. It uses one temporary SQLite database and an owned child process. All rows are fictional; there are no packages, model calls, network services, credentials or user requests.

Worker A is the child. It reads a source revision and body together, closes that read connection and waits on an explicit message. The parent driver acts as worker B through a separate database connection: it commits revision 2 to source and cache, optionally deletes the cache row, then releases A. This ordered overlap reproduces the late-writer condition without relying on a sleep or a fast machine. It is a publication experiment, not a throughput or response-latency benchmark.

A publication fence is the condition that must still hold when saved work is made available. Here it is the captured source revision matching the authoritative source inside the same database write transaction. A cache row is a derived copy; its absence cannot establish which source revision is current. Follow the visual, then make your own predictions before opening the program output.

UNDERSTAND THE SYSTEM

Stop a late writer from publishing an older copy

A child process captures revision 1 and waits. The parent driver acts as worker B, commits revision 2, then releases A. These frames explain four fresh local cases; the visual does not execute them or establish distributed freshness.

FOLLOW THE WORK

Watch one example, step by step.

5 authored stepsYou control the pace
01 / EXPLORE THE PARTSControls loading · written explanations below
Direction of information or workReturn / feedback

WHAT THIS PART DOES

Authoritative row

The source row binds revision and body. Both are read together. The correct publication policy compares against this row within the same write transaction as cache publication.

CONNECTED TO
  • Read pair: A's captured input
  • Advance: Worker B · parent
Read the full worked example
  1. 01
    Capture before the change

    A reads revision 1 and its body together, then waits. The source can change while that work is held. The captured pair stays evidence of A's input, not evidence of the source's current state.

    PROCESS OBSERVATION: A captured revision 1

  2. 02
    Publish the newer copy

    B commits revision 2 and its cache copy through a separate connection. Only then does the parent release A. Inspect B's observed source and cache before considering A's publication result.

    BEFORE A RESUMES: Source 2 · cache 2

  3. 03
    Compare naive and guarded

    In naive, A replaces the newer copy with revision 1. In the separately reset guarded case, checking the source revision and publication inside one write transaction rejects A, retaining cache revision 2. Check rowcount and the actual stored pair.

    INDEPENDENT CASES: Naive: cache 1 · guarded: cache 2

  4. 04
    Delete the cache fence

    In row-only-deleted, B's cache row is removed before A resumes. A policy comparing only an existing cache row now admits the old candidate. The source remains revision 2 while the cache is repopulated with revision 1.

    ROW-ONLY POLICY: Missing cache → stale copy admitted

  5. 05
    Keep the authoritative fence

    Guarded-deleted starts fresh with the same deletion. The source remains revision 2, so A is rejected even though the cache is absent. The result is a miss requiring a fresh build, not permission to return A's old body.

    AUTHORITATIVE CHECK: Source 2 · cache absent · A rejected

Read the connections in plain English
  1. 01
    Authoritative row → A's captured input

    Capture revision and body together; the candidate's provenance belongs to this snapshot.

  2. 02
    A's captured input → Late publisher A

    Wait on an explicit process message while retaining the old candidate.

  3. 03
    Worker B · parent → Authoritative row

    B commits a new authoritative source revision and body before A resumes.

  4. 04
    Worker B · parent → Derived cache row

    B also stores the revision-2 copy. The deleted cases subsequently remove only that copy.

  5. 05
    Late publisher A → Publication rule

    Evaluate the chosen publication policy against the now-changed state.

  6. 06
    Publication rule → Derived cache row

    A rejected candidate changes no cache row. It does not invent a replacement body or return one to a user.

Check your understanding: The cache entry is gone. Does that make A's captured revision safe to publish?

No. Missing cache data is not an authoritative freshness check. In guarded-deleted, source revision 2 rejects A's revision 1 within the publication transaction, leaving a miss. The lab does not test a later read-to-response race, current authorization, stampede control or a separate remote cache.

8. Compare four independently reset cases

Spend five minutes predicting, eight running and inspecting, four explaining the deleted-row difference and eight on a receiving check.

Code example
python3 --version
python3 fde-cache-publication.py --all > publication-results.json
python3 fde-cache-publication.py --case guarded-deleted
Fresh caseState before A publishesPolicy used by AExpected stored result
naiveSource 2, cache 2Unconditional replacementSource 2, cache 1
guardedSource 2, cache 2Authoritative source check and write in one transactionSource 2, cache 2; A rejected
row-only-deletedSource 2, cache absentCompare the cache row only when it existsSource 2, cache 1
guarded-deletedSource 2, cache absentAuthoritative source check and write in one transactionSource 2, cache absent; A rejected

Read the actual revision and body, not only the policy name. captured_a records the coherent old input; b_after_commit records the newer source/cache; cache_before_a shows whether the copy was removed. Compare publication with authoritative_source_after and cache_after. A zero publication row count and an absent cache are legitimate in the last case. No new copy has been built, and this program has not returned a body to a user.

Find the source read, B's commit, the explicit release message, and A's publication transaction in the code. The guarded check uses BEGIN IMMEDIATE so another writer cannot change this local database between that check and the write. The read/check/write boundary matters: reading revision 2 earlier, ending the transaction, then unconditionally writing later would introduce another gap.

9. Challenge the fence after eviction

Compare row-only-deleted directly with guarded-deleted. The original source has not disappeared. Removing a derived copy removes a row-only policy's evidence, but not the authoritative revision. An empty cache is not a reset of source history. Do not fix the case by relabeling revision-1 content as revision 2 or assuming that a fresh time-to-live makes old input current.

Now describe a changed architecture: source is in one service and cache is in another. This program's SQLite transaction cannot span those independent systems. Name a testable receiving contract—such as immutable revision keys with an authoritative current-revision selection—and the failure windows that still need proof. Do not claim the local lock supplies a remote transaction. Revision identifiers must identify the same source lifecycle; reused revisions after a restore or document replacement would need an additional generation identity.

Successful publication also does not guarantee that a later reader sees the latest source at response time. That is a separate read-and-return consistency boundary. Current permission, revoked access during a wait, stampede control, producer failure, capacity limits and performance remain untested by this companion.

10. Receive the publication evidence

Assign candidate author, source/cache owner and receiving engineer. Each participant predicts one case before discussing it. The receiver runs the deleted-row pair without the author's narration, identifies the two different comparison sources and explains why the correct result can be a miss. Record help, takeover and any incorrect first explanation. Solo work is self-review.

Text example
Candidate file / revision or digest:
Case and first prediction:
A captured revision and body:
B committed source and cache:
Cache before A / deletion observed:
Publication policy / comparison revision / decision / rowcount:
Actual source and cache after A:
Exact check-and-write transaction location:
My contribution / receiving action / assistance:
Boundary still untested / responsible receiving owner / next check:

The source/cache owner must define authoritative revision identity and mutation rules. The application owner must define reader freshness and current permission. The receiving engineer reproduces the selected cases and records missing evidence; a pod lead coordinates these responsibilities without treating a successful command as approval to deploy or proof of learner independence.

The companion and its fixtures are original. SQLite transaction semantics and Microsoft cache-aside consistency considerations were checked on 26 October 2026; they support the local transaction and consistency distinctions, not a claim that this fixture models a managed distributed cache.

Further reading (Microsoft, Anthropic and OWASP checked 25 October 2026; AWS checked 22 October 2026):

These references support further study. The fictional case, experiment and teaching diagram are original LockedIn Labs material; no provider affiliation or certification is implied.

8. Inspect HTTP reuse through actual requests

Continue with the HTTP caching proof workshop. It uses an owned loopback origin to expose a fresh wrong-language hit, compare Vary-aware selection, inspect a bodyless 304 beside its saved representation, and distinguish no-cache, no-store and Vary star. Reverse the first language and have a receiver reproduce the result from exact headers and origin evidence. This separate transport exercise does not replace current application access or source-validity checks. It is not a browser/CDN configuration or deployment.

9. Share overlapping misses without borrowing a guarantee

Run the coalescing proof workshop to compare actual duplicate builds, shared in-flight work, leader failure and waiter timeout. A three-caller change and a separate current-source observation keep execution counts distinct from freshness and caller success. Rotate the receiving role and retain individual observations. This is one process with owned local threads; production cache reuse, current authority and cross-replica behavior remain separate contracts.

Before you move on

Keep the evidence of your work.

  • Eight cache predictions compared with actual local rows.
  • Separate stale-source and revoked-permission defect reports.
  • A scoped reuse contract naming current dependencies and untested concurrency.

Keep these in your own working copy. Reading this page does not save work or record completion.

Suggested next free session

Investigate retrieval before trusting the answer

Carry source freshness and current authority into retrieval and answer preparation. This is a suggested sequence; choose the practice that addresses your current gap.

Open the next free guide

Free account

Give your practice a home.

Try a role exercise with account drafts and a downloadable worksheet. Keep the files you made in this guide in your own working copy.

Create a free learning account

Guided training · by application

Build toward a program.

Request structured lessons and a training seat. Scope, schedule, feedback arrangements and tuition are confirmed in writing before you commit.

Explore a training application
Have Academy access?

Use your existing training seat to open worked explanations and practice in the related lesson. Creating a free account does not grant a seat.

Open the related Academy lesson →
Back to top ↑