You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
perf(cloudflare): cut KV data cache round trips from 3 to 2 per tagged hit (#3187)
* perf(cloudflare): cut KV data cache round trips
A cold get() made three sequential KV round trips: the entry, then the entry's
own tag markers, then the caller's soft-tag markers. Soft tags are known before
the entry read, so their markers now start with it, and the second hop reads
only the entry tags the first hop did not already cover. Markers go through KV's
bulk get() in chunks of 100, so a page with many tags costs one subrequest per
chunk instead of one per tag. A tagged hit now takes two round trips and an
untagged hit takes one.
Entry reads also gain an opt-in entryCacheTtlSeconds option that sets KV cacheTtl
on the entry key alone; it stays off by default because a colo that cached the
key can then serve a superseded value for that long. Tag markers never take it,
since a colo cache on a marker would hide a revalidateTag from that colo for the
same window.
* fix(cloudflare): stop a KV marker read failure from breaking a miss
- await the entry read alone, so a miss returns without the soft-tag batch and survives its failure
- attach a catch to the ignored marker promise to prevent an unhandled rejection
- check the locally cached entry tags before the second hop, which restores the short circuit the previous commit dropped
- correct the entryCacheTtlSeconds doc: markers keep the KV default cacheTtl of 60 s rather than always reaching the central store
- add a fail helper to the tracing KV double, with cases for the miss, hit, and cached invalidation paths
* fix(cloudflare): respect tagCacheTtlMs in the invalidation fast path
- check cached entry tags first, so a failed soft-tag batch cannot mask a known invalidation
- add requireFresh to _hasRevalidatedTag, so a pre-prime check ignores a marker past tagCacheTtlMs
- keep a marker written at or after the read start, so a detached prime cannot overwrite a newer revalidateTag
- snapshot the store at call time in the tracing KV double, so a held read cannot see a later write
- add four tests; all four fail against 7623ce3
* fix(cloudflare): keep speculative KV reads request-scoped
* fix(cloudflare): order concurrent KV tag primes
* fix(cloudflare): re-prime KV tags after cache reset
* fix(cloudflare): preserve KV tag validation across reset
* fix(cloudflare): avoid deleting newer KV entries
---------
Co-authored-by: James <james@eli.cx>
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -703,7 +703,7 @@ The KV data adapter reads `env[binding]` at runtime, so add the matching KV name
703
703
}
704
704
```
705
705
706
-
`binding` defaults to `VINEXT_KV_CACHE`, so `kvDataAdapter()` with no options works as long as that's your binding name. Other options: `appPrefix` (namespace cache keys to isolate multiple apps in one KV namespace), `ttlSeconds` (default KV `expirationTtl`, default 30 days), and `tagCacheTtlMs` (in-memory tag-invalidation cache TTL, default 5s).
706
+
`binding` defaults to `VINEXT_KV_CACHE`, so `kvDataAdapter()` with no options works as long as that's your binding name. Other options: `appPrefix` (namespace cache keys to isolate multiple apps in one KV namespace), `ttlSeconds` (default KV `expirationTtl`, default 30 days), `tagCacheTtlMs` (in-memory tag-invalidation cache TTL, default 5s), and `entryCacheTtlSeconds` (optional KV edge-cache TTL for entry reads; tag markers keep KV's default).
707
707
708
708
When `cdnAdapter()` is used in a Cloudflare build, vinext emits two Worker
709
709
entrypoints and configures Workers Cache only on the response entrypoint. The
0 commit comments