Docs / Caching and ETags
Caching and ETags
Strong content ETags on five routes, 304 on a match, and a Cache-Control table you can build a poll interval from. A conditional poll costs headers, not items.
One tag per URL, including its query string
The ETag is a strong, content-derived SHA-256 prefix. Send it back as If-None-Match; an unchanged representation answers 304 with no body and no billable items.
The ETag scheme, conditional requests and Cache-Control
Source: docs/API.md §7.
7.1 Strong content ETags
An ETag is a quoted strong entity-tag (no W/ prefix), 34 characters long:
etag: "98bbb69edbaef9582d42c71fb345a760"Captured at policy 2026-11-04.2. The bumper is in the hashed input, so this exact tag is no longer the one the serving app answers — the shape and the derivation below are what the section pins; read the current tag from a real response. It is the first 128 bits (32 hex characters) of a SHA-256 over the canonical JSON of this envelope:
{"v": 1, "namespace": "feed:en", "policy_version": "<the version in /v1/meta>", "body": <response body>}Canonical JSON is sort_keys=True, separators=(",", ":"), ensure_ascii=False, allow_nan=False, UTF-8. Namespaces are items, item:<id>, related:<id>, feed:<locale>, feed:<locale>:<category> (a filtered feed is its own resource) and meta. The FXStreet surface has its own namespaces (fxs:list|…, fxs:post|…, fxs:culture:all, fxs:tag…) built from every input that decides the body — culture, filter/productFeature, tagIds, category, page/take, since/until, bodyType, casing, ids — so two different queries can never share a tag (see §7.7).
Three properties follow, all verified:
- Deterministic. The same body produces the same tag in a different process. Verified by recomputing
"98bbb69edbaef9582d42c71fb345a760"for the same captured feed body in two separate Python processes. - Content-derived, never clock-derived. There is no timestamp in the input, so a timestamp cannot fake a content change and a content change cannot hide behind one.
- Policy-aware.
policy_versionis part of the hashed input, so a policy bump that changes nothing else still invalidates every stored copy. It is additive input, so it can only cause an unnecessary200, never a stale304.
A real content change does change the tag: adding one assets.title_image_url to a feed changed its tag from "87631c6c…" to "693db3e8…" (measured at policy 2026-11-04.1). A policy bump alone does too: one unchanged feed body hashes to "87631c6c…" under 2026-11-04.1 and "298cb491…" under 2026-11-04.2. The value in these examples is the version serving at capture; read the current one from /v1/meta → policy_version.
Which routes carry one: /v1/items, /v1/items/{item_id}, /v1/items/{item_id}/related, /v1/feed/{locale}, /v1/meta, and every GET on the FXStreet surface (§7.7). /v1/search, /v1/digest/*, /v1/stats, the run routes, /v1/usage and /v1/health carry none. /v1/images/{key} carries a file-derived ETag and Last-Modified but does not evaluate conditional requests (see §7.5).
7.2 Conditional requests and 304
If-None-Matchuses weak comparison (RFC 9110 §13.1.2): a client sendingW/"x"matches the server's strong"x"; a comma-separated list and*are honoured.If-Modified-Sinceis evaluated only where aLast-Modifiedexists:/v1/feed/{locale}(the snapshot's stablegenerated_at),/v1/items/{item_id}(the item'supdated_at) and/v1/items/{item_id}/related(the newest servedupdated_at). HTTP dates have one-second resolution, so the comparison truncates to whole seconds.If-None-Matchtakes precedence overIf-Modified-Since(RFC 9110 §13.1.3).- A
304carries the sameCache-Control,ETag,Vary(andLast-Modifiedwhere the 200 would have had one) and no body:
HTTP/1.1 304 Not Modified
etag: "98bbb69edbaef9582d42c71fb345a760"
vary: Authorization
last-modified: Wed, 04 Nov 2026 21:35:54 GMT
cache-control: public, max-age=60- A
304delivers no items, so it bills no items (one request is still counted) and carries nocount— keep the previous rendering. - Measured:
If-None-Matchwith the stored tag →304; withW/<tag>→304;If-Modified-Sincealone on the feed →304;/v1/metawithIf-Modified-Sinceonly →200(it has noLast-Modified);/v1/searchand/v1/digest/*with anyIf-None-Match→200.
7.3 Cache-Control table
| Route | Cache-Control |
|---|---|
/v1/feed/{locale} | public, max-age=60 |
/v1/items | public, max-age=30 |
/v1/search | public, max-age=30 |
/v1/items/{item_id} | public, max-age=300 |
/v1/items/{item_id}/related | public, max-age=300 |
/v1/digest/{locale}, /v1/digest/{locale}/{day} | public, max-age=300 |
/v1/meta | public, max-age=3600 |
/v1/images/{key} on a hit | public, max-age=31536000, immutable |
/v1/site/images/{key} on a miss | public, max-age=N (5 s pending, 10 s unavailable/lost, 15 s unknown, 60 s failed, 300 s impossible key; X-Ember-Image-Miss names the reason) |
/fxs/v4/{culture}/post/... (list shapes) | private, max-age=30 |
/fxs/v4/{culture}/post/{id} | private, max-age=60 |
/fxs/v4/culture/all, /fxs/v4/{culture}/tag, /fxs/v4/{culture}/tag/filter/{ids} | private, max-age=3600 |
/v1/health | no-store |
/v1/stats, /v1/runs, /v1/runs/{run_id}, /v1/sources/health, /v1/usage, /v1/usage/history, /v1/admin/usage | no-store |
POST /v1/refresh | no-store |
any 4xx/5xx | no-store, with ETag/Last-Modified stripped (ErrorCacheGuard) |
a 404 on /v1/site/images/{key} | the miss row above (the one bounded exception) |
The last two rows are structural: a 400, 401, 404, 429, 5xx — and every operator route — is stamped no-store and has its validators removed, so a CDN in front of the API can never store an error or an admin answer. Verified on a 400: cache-control: no-store, no ETag. The one exception is a public image miss: a key that a feed advertised a moment before its bytes existed is the answer a browser and an edge must be allowed to remember for a few seconds, so a 404 under /v1/site/images/ may keep a public, max-age the route published, bounded at 300 s by the guard. Everything else, including the credential-keyed /v1/images/{key}, keeps no-store.
7.4 Vary
Every conditional route sends Vary: Authorization on both 200 and 304. The responses are public but the request is authenticated, so a shared cache must key on the Authorization header; without it, a cache could answer a different — or an unauthenticated — request with a stored body.
/v1/search and the edition routes (/v1/digest/*) carry validators too and answer 304 under the same contract; they send Vary: Authorization like the rest. A shared cache must key on Authorization for them as well, so a CDN in front of them is safe only with that key.
The FXStreet surface is credential-keyed and private, and it sends Vary: Accept-Encoding, Authorization on every 200 and every 304 (one comma-separated value is the RFC 9110 §12.5.5 spelling of two Vary fields). Authorization keeps a cache that stores the response anyway from answering another credential with it; Accept-Encoding is required because the body may be compressed, so a gzip copy and an identity copy are different stored responses. Vary is therefore not the bare Authorization the /v1 routes send, and /v1 is unchanged by this.
7.5 Images
A hit is Cache-Control: public, max-age=31536000, immutable with X-Content-Type-Options: nosniff, a file-derived ETag and a Last-Modified. The bytes for a given key never change, so this is safe to cache indefinitely. A conditional request with that ETag still returns 200 and the full body (measured): the image route does not evaluate If-None-Match.
7.6 Feed stability
/v1/feed/{locale} has a stability guarantee: generated_at is the newest run's finished_at (its started_at while that run is still going), and items published after that instant are held back, so two polls inside the same run window return the same set and the same ETag. With no run in the log at all, it is the newest served item's updated_at; an empty database anchors on the fixed value 1970-01-01T00:00:00.000000Z. It is never a live clock read, which is what lets an unchanged feed be revalidated.
7.6b Typed public mirror responses
GET /openapi.json used to declare every 200 as schema: {}: 52 paths / 55 operations with no response body described at all. That made the API unusable as a drop-in FXStreet substitute — a generated SDK had nothing to type, so a consumer had to hand-write (and hand-keep) the models. The public reads below publish a CLOSED schema (additionalProperties: false at every level) derived from the payloads the LIVE mirror served:
| Route | Component | What it describes |
|---|---|---|
GET /v1/site/feed/{locale} | SiteFeed | locale, generated_at, disclaimer, items[] |
GET /v1/site/items | SiteItemsPage | items[], next_cursor, count, disclaimers; disclaimer only when ?locale= filtered the page |
GET /v1/site/items/{item_id} | SiteItemDetail | the list item plus disclaimer and provenance |
GET /v1/site/meta | SiteMeta | schema_version, api_version, locales, categories, policy_version, default_locale, limits.max_page_size |
GET /v1/site/markets | SiteMarkets | status, as_of, delayed, items[], sources[], detail |
GET /v1/site/storyline/{item_id} | SiteStoryline | Exact report and edition, dated entries, and optional public share_url per entry |
Three facts a client can now rely on that the prose alone made easy to get wrong:
- Images live under
assets, never at the item's top level:assets.title_image_url,.title_image_srcset,.title_image_aspect,.title_image_ai_generated,.title_image_alt,.title_image_credit,.title_image_licence,.body_images[]. Each is present only when there is a picture to describe. market_data.symbolmay benull(withprice: 0.0) on an item with no attached quote — the documented sentinel (§11), not an absence.market_dataitself isnullonly on rows written before the field existed.provenanceis opt-in on list surfaces (?include=provenance) and always on the single-item read, which is whySiteItem(the list row) declares it optional andSiteItemDetailrequires it.
components.securitySchemes is still null, deliberately: the mirror is keyless by design (§2, §5a), and the metered surface advertises its credential through the prose in §3 rather than a security scheme. Typing those routes is a separate change.
7.7 The FXStreet surface (/fxs/*)
Every GET on the compatibility surface supports a conditional request. It carries the same kind of strong, body-derived ETag as /v1 (same envelope, same 128-bit truncation), a private Cache-Control, and Vary: Accept-Encoding, Authorization:
HTTP/1.1 200 OK
etag: "0b6a3f0a4f4a4c8b1f1c6c0c1f1e2d3c"
cache-control: private, max-age=30
vary: Accept-Encoding, AuthorizationA poll whose copy is current is answered 304 with the same ETag, the same Cache-Control, the same Vary and no body; the body is byte-identical to the 200 whenever the tag matches (that is what makes the tag a validator rather than a hint). A tag that no longer matches is a full 200 with the new body.
| Route | Cache-Control | ETag / 304 |
|---|---|---|
/fxs/v4/{culture}/post/... (every list shape) | private, max-age=30 | yes |
/fxs/v4/{culture}/post/{id} (and /{id}/{bodyType}) | private, max-age=60 | yes, plus Last-Modified from the item's updated_at |
/fxs/v4/culture/all | private, max-age=3600 | yes |
/fxs/v4/{culture}/tag | private, max-age=3600 | yes |
/fxs/v4/{culture}/tag/filter/{tagIds} | private, max-age=3600 | yes |
What the tag is derived from: the rendered response body — never max(updated_at) and never a row count, because either would answer 304 after an in-place edit that left the timestamps alone and hand the client its stale copy. The namespace adds every input that decides the body: the route, the culture/locale, filterType, productFeature, tagIds, category, page/take, since/until, bodyType, casing, ids mode, and the compliance policy_version. Two different queries therefore never share a tag. The credential is deliberately not part of the namespace: no field of the body is derived from the key (the key decides whether the body is served and what is metered), and authentication runs before the conditional decision.
Metering is unchanged. A 304 still records the same delivered items its 200 would (the per-key meter counts unique item ids per month, so re-recording them cannot double-bill), which also holds when a short-TTL server-side cache answers the 304.
For the namespace's ids/casing interaction and the residual divergence from FXStreet's documented camel shape, see docs/FXSTREET_COMPAT.md.
The caching contract for a client
Source: docs/API.md §9.
Conditional requests are live on the five ETag routes, so the recommended loop is a conditional GET, not a blind poll:
- Store the
ETagof every200you receive on/v1/feed/{locale},/v1/items,/v1/items/{id},/v1/items/{id}/relatedand/v1/meta. - On each later poll send
If-None-Match: <stored ETag>. - On
304, keep the previous rendering and change nothing — the body is unchanged and no item was billed. - On
200, replace the rendering and store the newETag. - Never reuse an ETag across routes or across different query strings; a
/v1/itemstag belongs to that exact query. /v1/searchand/v1/digest/*answer304under the same contract; a304still counts as one metered request and delivers no items.
A working loop in both languages is in docs/INTEGRATION.md §6.
A conditional poll in Python and Node
The reference loop lives in docs/INTEGRATION.md §6.2 and §6.3; the two pages below are reproduced from there.
Python
import json
import os
import time
import urllib.error
import urllib.request
BASE = os.environ.get("NEWS_BASE", "https://vg.tempproject.online")
KEY = os.environ.get("NEWS_KEY", "")
INTERVAL = 60 # seconds; never poll faster than the route's max-age
state = {} # path -> {"etag": str, "body": dict}
def poll(path):
entry = state.setdefault(path, {"etag": None, "body": None})
req = urllib.request.Request(BASE + path)
req.add_header("Authorization", f"Bearer {KEY}")
if entry["etag"]:
req.add_header("If-None-Match", entry["etag"])
try:
with urllib.request.urlopen(req, timeout=15) as res:
entry["body"] = json.loads(res.read().decode("utf-8"))
entry["etag"] = res.headers.get("ETag", entry["etag"])
return 200
except urllib.error.HTTPError as exc:
if exc.code == 304:
return 304 # unchanged: keep entry["body"], cost is headers only
if exc.code == 429:
time.sleep(int(exc.headers.get("Retry-After", "60")))
return 429
raiseDrive it on a timer; on 304, re-render nothing and keep what is on screen. On 200, replace the rendering and store the new tag. Keep one tag per URL including the query string: a tag from /v1/items?limit=50 must never be sent with /v1/items?limit=200.
Node
const BASE = process.env.NEWS_BASE || "https://vg.tempproject.online";
const KEY = process.env.NEWS_KEY || "";
const state = new Map(); // path -> { etag, body }
async function poll(path) {
const entry = state.get(path) || { etag: null, body: null };
const headers = { Authorization: `Bearer ${KEY}` };
if (entry.etag) headers["If-None-Match"] = entry.etag;
const res = await fetch(BASE + path, { headers });
if (res.status === 304) return 304; // unchanged: entry.body stays as it was
if (res.status === 429) {
await new Promise((r) => setTimeout(r, Number(res.headers.get("Retry-After") || 60) * 1000));
return 429;
}
if (!res.ok) throw new Error(`${res.status} ${path}`);
entry.body = await res.json();
entry.etag = res.headers.get("ETag") || entry.etag;
state.set(path, entry);
return res.status;
}