Skip to content

ADR: Cache headers

ADR: Cache headers

Status
accepted
Date
2026-09-02
Shipped as
1.0.0.20

In plain words

Browsers keep copies of files so pages load faster. This decides what they may keep: the code files, whose names change whenever their contents change, are kept for a year, and the page itself is checked with the server on every visit, so a new version reaches every visitor the next time they load the site.

What that is worth: users get fast pages and never a stale mix of old and new, and the organization ships a fix knowing every visitor sees it, with no support calls asking people to clear their cache.

Context

Steve's phone kept showing the dark sidebar after the light one had shipped. Measured on the live site before this change: the page itself, /, was served with an ETag and a Last-Modified date and no Cache-Control header at all. HTTP lets a browser reuse a response like that without asking, for a stretch it estimates from the file's age (the heuristic freshness rule in RFC 9111). A browser that held the old page could keep using it, and the old page names the old bundle files, which it held under the same rule. The API and the documents carried no cache headers either.

The old fix, from the days of hand-written script tags, was to append the file's date to its address, app.css?v=20260902, so a changed file had a changed address and no cache could confuse the two. A React app built with Vite does the same thing without anyone typing a date: every bundle file is named after a hash of its own contents, assets/index-a1b2c3d4.css, and index.html is rewritten at build time to point at the new names. A change in the CSS is a change in the file name, every build, with no hand on it. What the hash cannot fix is index.html itself, which keeps its address forever, and that is the file the phone was reusing.

Decision

Three cache rules, set in one place by one middleware, chosen from the shape of the address:

  • Hashed bundle files, /assets/*: public, max-age=31536000, immutable, a year. Their names change when their contents change, so a stale copy is impossible, and a browser may keep them as long as it likes, which is what makes the second visit fast. Only a 200 gets this header; a missing file is never remembered for a year.
  • Everything that can change under the same address: no-cache. The page, the API, the documents, the version. A browser may keep a copy but must ask before using it. The page answers those asks with 304 Not Modified from its ETag, which costs one round trip and no bytes.
  • The photo set, /api/images/*: unchanged, one day, as it already was. The photos do not change between builds.

The date in the address is not needed and not used. The hash in the file name is the same idea, done by the build, for every file, every time.

In the code

The rules, read from this build (api/TheYard.Api/Shared/Wiring/RequestPipeline.cs):

// Cache rules (ADR-015), from the shape of the address. Registered before the
// files and the endpoints so its rule is in place on every response either writes. Vite names every
// bundle file by a hash of its contents, so /assets/* can be kept for a year
// and never goes stale: a new build has new names. Everything that can change
// under the same address (the page, the API, the documents) says no-cache, so
// a browser asks before reusing it. The photo set keeps its own one-day rule
// below, and a response that already chose its rule is left alone.
app.Use(async (context, next) =>
{
    context.Response.OnStarting(() =>
    {
        var response = context.Response;
        if (!response.Headers.ContainsKey("Cache-Control"))
        {
            bool hashedBundleFile = context.Request.Path.StartsWithSegments("/assets")
                && response.StatusCode == StatusCodes.Status200OK
                && !(response.ContentType ?? "").StartsWith("text/html", StringComparison.OrdinalIgnoreCase);
            response.Headers.CacheControl = hashedBundleFile
                ? "public, max-age=31536000, immutable"
                : EdgeKeeps.BrowserRuleFor(context) ?? "no-cache";
        }
        // The catalogue's two reads may be kept by the edge for a few seconds, and what
        // only a deploy changes for a day (EdgeKeeps); the browser's rule above is unchanged.
        CatalogueReads.LetTheEdgeKeep(context);
        EdgeKeeps.LetTheEdgeKeep(context);
        return Task.CompletedTask;
    });
    await next();
});

Live from api/TheYard.Api/Shared/Wiring/ResponseKeeping.cs, region cache-headers, read from this build at 99df7a8.

The proof is api/TheYard.Tests/CacheHeaderTests.cs: the API, the documents and the version say no-cache; a missing bundle file says no-cache rather than immutable; a photo keeps its day.

Consequences

  • A deploy is visible on the next load, on any device: the browser asks for the page, gets the new one, and the new one names new bundle files.
  • A device that loaded the site before this shipped still holds the old page under the old rule until it reloads once; after that the rules above apply.
  • The edge in front of the site was measured the same day as passing API responses through without caching them (Cache-Status fwd=miss), so the rules above reach the browser as written.
  • The Admin tab, the version endpoint and the documents are fetched fresh every time. They are small, and being current is their whole job.

Where it sits

The cache rules live in the host Api, in one inline middleware in Composition/RequestPipeline.cs (region cache-headers) that picks a rule from the shape of the address. The rule for every address is read in one place, with the photo set's one-day rule as the one exception. The cost is a round trip on every visit for the page and the API, answered with a 304 when nothing changed. A bundler that did not hash file names would force versioned addresses back into the page.

Files

More of the code

The static file middleware, the photo set's own rule, and the fallback that answers only app routes (api/TheYard.Api/Shared/Wiring/RequestPipeline.cs):

// What: the page, the hashed bundle files and the photos, straight from disk.
// How: UseDefaultFiles turns "/" into "/index.html", and each UseStaticFiles
// answers a file it has and ends the request there; anything else carries on.
// Why here: ahead of routing, the user, the session and the store's warmth,
// none of which a file needs. Microsoft's order puts static files right after
// error handling for exactly this reason. Until the pipeline
// lane they ran last, so every file waited behind all of that, and the photos,
// which live under /api/images, waited for the catalogue to load after a roll.
// The cache rules above still wrap them, because those are registered first.
// The SPA fallback stays the last word (SpaRegistration.cs): it answers app
// routes with index.html, while an address that looks like a file stays a
// 404 rather than a page dressed as a script.
app.UseDefaultFiles();
UseDownloads(app);
app.UseStaticFiles();

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(imagesRoot),
    RequestPath = "/api/images",
    // The photo set is content-stable; let the browser's HTTP cache keep it
    // for a day instead of re-fetching 50 JPEGs per session.
    OnPrepareResponse = ctx =>
        ctx.Context.Response.Headers.CacheControl = "public, max-age=86400",
});

Live from api/TheYard.Api/Shared/Wiring/ResponseKeeping.cs, region static-files, read from this build at 99df7a8.

Addendum, 2026-09-28 (1.0.3.35): the edge is warmed after every deploy

The year-long rule above is why a hashed file costs nothing the second time. The first time is the edge's miss: the edge asks the origin, and until it has the file it has nothing to serve. Measured on the Cosmos DB site from Missouri at 10:30 CDT, before this change: the activity card's four chunks took about 700 ms on a miss (about 630 ms of it waiting on the origin) and 33 ms once the edge held them. Because every deploy renames every hashed file, the first visitor after every deploy paid that miss on every chunk they opened.

  • Both deploys warm the edge after the site answers (scripts/warm-edge.mjs, the step "Warm the edge" in deploy.yml and deploy-cosmos.yml). The script reads the build's file list off the site itself, through the public address: the page names its entry files and every script names the chunks it can load, so following those names reaches every file the build serves, with no manifest to publish. It asks for each file once, then for the Admin tab's public reads (/api/admin/activity for each window, /api/health, /api/admin/machines, /api/admin/pages), all with the deploy's own TheYard-SelfRead/1 (deploy) agent, so the Site activity card counts them as the site reading itself. A failure is a warning and never fails a deploy; DeployWorkflowTests holds the step to both workflows, after Verify.
  • What the warm-up can reach, and what it cannot. The edge caches a proxied response at the node that served it; each node keeps its own. A GitHub runner reaches the node nearest the runner, which warms the files for visitors near that node and not necessarily for one in Missouri. Netlify's shared layer that would carry one warm read to every node, the durable cache directive, applies to responses from Netlify Functions only, not to proxied responses (Netlify's caching overview, read 28 September), so it does not fit an edge that proxies to Azure. What does reach a given place is a read from that place, so the ship that pushes from Steve's machine in Missouri runs the same script against both sites once the roll answers.

Addendum, 2026-10-05 (1.0.3.76): measured again, and why the script still misses

Read from Missouri on 1.0.3.74, ten requests in a row for the hashed script on each site: six of twenty were hits and fourteen were misses, every miss marked stored. The headers this record sets are doing their job; the misses come from the edge keeping a separate cache per node, as the addendum of 28 September found, and from a site this quiet rarely landing on a warm one. Nothing in this repository can change that on the free plan. Netlify's shared durable layer still applies to its own Functions only. Serving the built files from the edge itself would end the misses, and it is priced in Edge deploy economics (ADR: Edge deploy economics, the addendum of 5 October). The numbers are on the Performance page.

Addendum, 2026-10-05 (1.0.3.77): the catalogue's reads leave compressed

The Performance page said on 17 September that server-side compression was not needed, because the edge serves everything text-shaped as Brotli. That holds for the browser's side of the edge. It does not hold for the hop behind it: the edge forwards every API read to Azure, and the listing came back to it as about 106 KB of plain JSON, which the edge then compressed to about 16 KB. Measured from Missouri on 1.0.3.74, the whole of that answer took 0.54 to 0.80 s straight from Azure, and the listing through the edge took 0.34 to 2.43 s to its first byte.

So the container now compresses the catalogue's two reads, the listing and the filter values (CatalogueReads), with Brotli or gzip, for any caller that asks. The level is the optimal one, which is Brotli's quality 4. The fastest level was tried first and sent 44 KB of the 106, because the serializer writes the answer in pieces and each piece is flushed through the compressor; at quality 4 the flushes cost little, and a hundred vehicles take about a millisecond. Nothing else is compressed. Those two bodies carry no secret, which is what keeps them safe from the BREACH attack: it needs a secret and text an attacker chooses in the same compressed body, and a session here travels in a cookie header, which response compression does not touch. Every other address leaves as it did. CompressionTests holds both halves, and the numbers after the roll are on the Performance page.

Addendum, 2026-10-05 (1.0.3.79): the edge's copy of the catalogue

Every API read said no-cache, so the edge forwarded each one to Azure and a visitor clicking through the listing waited on that hop every time. The listing and the filter values are now an exception for the edge alone. A 200 to either one carries, when the caller sent no cookie and no Authorization header and the answer sets no cookie, Netlify-CDN-Cache-Control: public, max-age=15, stale-while-revalidate=15: the edge may answer from its own copy for fifteen seconds and for fifteen more while it fetches a fresh one. The copy is kept per query string (Netlify-Vary: query) and per store (Vary: X-Yard-Store). The browser's rule does not change: Cache-Control still says no-cache, so a browser still asks every time.

What it costs, said plainly: a listing price or a sold flag can be up to thirty seconds behind on the listing grid. A vehicle's own page and its bids are not covered and are always read fresh, so the figure a buyer bids against is the live one. A signed-in request is answered fresh and never stored, so no shared copy holds anything a session produced. CacheHeaderTests holds the rule and the browser's unchanged no-cache; the numbers after the roll are on the Performance page.

Addendum, 2026-10-09 (1.0.3.110): the edge's copy of a page

The same rule, on the pages the rendering service draws. A page request that carries no cookie is answered with Netlify-CDN-Cache-Control: public, max-age=10, stale-while-revalidate=20 and Netlify-Vary: query,cookie=theyard_session, so the edge keeps a page drawn for nobody for ten seconds, per view, and a signed-in visitor is looked up under a key of their own. A request with any cookie is never kept. The browser still reads no-cache and asks every time. The decision and its cost are in ADR: A rendering service beside the API, the addendum on the edge's copy of a page; render/render.ts carries the rule and CacheHeaderTests holds the cookie's name to the API's.

Addendum, 2026-10-20: what only a deploy changes, the edge keeps for a day

Until today every document said no-cache to the browser and nothing to the edge, so each one was drawn by the origin on every read. The reason was sound: a document's live-source blocks and its version strip are read from the image, and a copy kept across a deploy could show yesterday's source under today's version. What makes a day safe is a purge on every deploy, and the deploy now sends one.

  • The rule. An answer that can only change on a deploy may be kept by the edge for a day, and the deploy purges it. Every document and diagram under /api/docs and the share card's picture /og.png now carry Netlify-CDN-Cache-Control: public, max-age=86400 (Shared/Edge/EdgeKeeps.cs), on the catalogue reads' terms: a 200 to a GET from a caller with no cookie and no Authorization header, setting no cookie of its own, so a session renewed on the way out never sits in a shared copy. The browser's rule is unchanged for the documents (no-cache, it still asks); /og.png keeps its name across deploys, so the browser may keep it a day too, the photo set's rule.
  • What stays out. The resume (/api/docs/resume) and About Steven (/api/docs/author): the Site activity card counts a visitor by the request that reaches the origin, and an edge copy would hide the two steps it watches. Also /api/version (the deploy proves the roll by it), everything under /api/admin, the sign-in, and the page itself, which keeps the rendering service's own ten-second rule. The listing keeps its fifteen seconds and nothing more. EdgeKeepsTests holds both lists.
  • The purge. "Warm the edge" in deploy.yml first asks Netlify's purge API to drop every copy the site holds (one request, by the site name configuration gives, Azure:Resources:Edge, with the token the roll already hands the site), then warms as it always has. Both Yard names are separate keys at the edge, so every document is kept twice and purged together. A failed purge is a warning, never a failed deploy; DeployWorkflowTests holds the purge before the warm.
  • No durable. The handoff asked for durable on the edge rule. Netlify reads that word on its own Functions' answers only (Netlify's caching overview, read again today, and the addendum of 28 September), and these come through its proxy from Azure, so the header leaves it off rather than claim a shared layer that is not there.
  • Unchanged. The bundle's scripts and stylesheets under /assets keep their year, immutable, by content hash. /favicon.svg is not served at all: the site's icon is written into the page as a data address, so no file rule applies to it. The Shed's own css/ and js/ keep their names and their ETag rule by their own record.
  • What it costs. A document read through the edge is no longer counted on the Site activity card's page counts, because the origin never sees it. The two steps the card follows a visitor through are kept out for that reason; the rest is the price of not drawing an unchanged document on every read.

What the edge keeps for a day (the documents, the diagrams, the share picture) is kept only from an anonymous request and sent with no Vary: Cookie. A Vary on the cookie would give every browser that holds any cookie at all a copy of its own, which is no shared cache; the rule it would protect is that a kept answer is the same for everyone, and that is held directly instead: EdgeKeepsTests reads a document and a diagram signed out and again signed in and asserts the same bytes. A HEAD is now read the way a GET is (kept when anonymous, never with a cookie or an Authorization header), where it was never marked.

Enforced by

2 rules in the rulebook cite this record, each held by a test on every release.

The rule What holds it In the last gate
The listing and the filter values leave compressed for a caller that asks, and no other address is compressed CompressionTests 30 of 30 passed
The listing and the filter values may be kept by the edge for seconds, and what only a deploy changes (the documents, the diagrams, the share picture) for a day; never for a request that carries a cookie, and never the resume, About Steven, the version, the admin reads or the sign-in; the browser is still told no-cache; and every address the edge card scores is one the edge may keep CacheHeaderTests, EdgeKeepsTests 66 of 66 passed
Store

The Yard, home

Steven StoutStaff .NET engineerRemote

Production .NET that stays up. Built with AI, measured on every version.

Steven Stout

Hi, I'm Steve. I build the systems that make delivery boring in the best way, then coach people inside them.

  • 200+

    production releases, none took the platform down

    Conway Investment Research, 2019 to 2024. Sole engineer for the first three years on a live financial advisory platform.

    See how
  • 50%

    shorter release cycle

    Storee Construction, 2024 to 2026. Four ASP.NET applications onto one .NET 10 platform on Azure, with a four-person team I hired and mentored.

    See how

01Verified

Steven Stout

A real person, and the work is mine.

  • Identity

    Checked by LinkedIn, not by me.

    LinkedIn verified my government ID.

  • Running system

    You are looking at it.

    Version 1.0.5.273 is live. Nothing ships unless it passes the automated gates first.

That's who I am. Here's how I work.

02Strengths

Ten strengths, each with the proof beside it. The numbers match my resume and LinkedIn, and the live ones are read from this site as you look.

  • 01

    Keeps production alive

    200+ releases on a live financial platform, and none took it down. Sole engineer for the first three years.

    See the Conway work

  • 02

    Simplifies messy systems

    Four ASP.NET applications onto one .NET 10 platform on Azure, and a release cycle 50% shorter.

    See the Storee work

  • 03

    Marries dev and infrastructure

    Blue-green releases at Storee that flipped in about 5 seconds with nobody signed out, and Azure Front Door at two employers.

    See this site's cloud

  • 04

    Designs data that holds up

    White-label clients on one shared database, the isolation built into the data, and no cross-client issues.

    See the Conway work

  • 05

    Keeps AI-written code honest

    15 quality numbers that may only improve: 273 releases in a row with none worse.

    See the quality numbers

  • 06

    Resourceful

    $30,000+ cut from Azure and vendor spend at Conway. This site's Azure bill is public, resource by resource.

    See the bill

  • 07

    Builds people up

    Hired and mentored a four-person team. 13 colleagues recommend me by name.

    Read the recommendations

  • 08

    Takes ideas to production

    This site: designed, built and run solo, with 352 versions measured through one gate.

    How it was built

  • 09

    Writes clearly

    Posts on real engineering problems, in plain words.

    Read the blog

  • 10

    Owns decisions

    153 decision records, each with its tradeoff and the call I made.

    See the decision records

Built with AI. Gated so quality never slides.

Steven Stout’s showcase: a used-vehicle auction on .NET and React, built and run by one engineer, live on Azure, with its decisions written down.

No quality number has gotten worse at any release since 1.0.5.1 on 10 November: 273 releases in a row.

One engineer, an AI agent and a gate that checks 15 quality numbers on every release. 352 versions measured, with every result public, the worst days included.

82 releases in the last 7 days, each through the same gate.

Async methods with no CancellationToken, may only fall

11091.0.3.1391.0.5.2731.0.4.115, the ratchet
Every number, on the Quality page

TheYard, right nowLive

Answering in

unread

02505007501,000

server time at p95, the usual five minutes of the last day.

Azure this month

unread

the bill, by resource, read from Azure. The Admin tab shows every line.

Since the last roll

unread

 

rolled in place by the pipeline, behind one gate.

People who have visited

unread

30 days agotoday

Scanners, my own tools' and my own reads left out.

03Start here

04Where teams are heading

How I see engineering with AI, and the setup on this site that backs it.

AI-augmented teams · Architecture and ownership

AI writes more of the code. Someone still has to own what ships.

Teams are going to be heavily AI-augmented. That moves the senior job toward architecture and technical ownership: deciding what to build in pieces small enough to verify, and owning what ships.

  • Task tracking will get automated too. Judgment stays human: seeing a design fail at scale before it does.
  • On this site the AI's first design held the whole catalogue in memory. I caught it when the App Service plan hit 82 per cent and moved the work to the store.

What the AI wrote, what I decided

07Tech stack

  •    
  •    
  •    

Read from the build, never typed by hand

What TheYard runs on

What we use, where it runs, its AWS twin, the version as built, and the file that proves it.

Cloud patterns, not one vendor: every Azure piece in this stack has a named AWS twin. Mapped, not yet run on AWS.

  • .NET 1114 projects
  • React 19.3TypeScript 7.0
  • Azure9 Bicep files
  • 11GitHub Actions workflows
The whole stack, with the file that proves each line

The last release the gate stopped was 1.0.5.258 on 2 December, at its browser 1 of 2 job.

08How it is built

09How it is run

10Who and why

Next step

11What has to work, where is it today, and what does success look like?

Book 20 minutes opens an email to me with those three questions in it, and I answer with a time.

Book 20 minutes

Your email app should have opened with this message. If it did not, copy it and send it from any mailbox.

Or message me on LinkedIn