fix(sdk): refresh cache writes in LRU order#61
Conversation
Greptile SummaryThis PR ports the LRU write-refresh fix from upstream RhysSullivan#1118, ensuring that re-writing an existing key in the in-memory fallback cache moves it to the tail of the Map's insertion order so
Confidence Score: 5/5Safe to merge — the change is a single-line delete-before-set that mirrors an identical pattern already present in the The fix is minimal and self-contained: one No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["cache.set(key, value)"] --> B["evictExpired(now)"]
B --> C{"key already\nin Map?"}
C -- "yes (before fix)" --> D["rows.set(key, …)\n(key stays at original position)"]
C -- "yes (after fix)" --> E["rows.delete(key)\nrows.set(key, …)\n(key moves to tail = newest)"]
C -- "no" --> F["rows.set(key, …)"]
E --> G["evictCapacity()"]
F --> G
D --> G
G --> H{"rows.size >\nCAPACITY?"}
H -- yes --> I["delete oldest entry\n(first in insertion order)"]
I --> H
H -- no --> J["done"]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["cache.set(key, value)"] --> B["evictExpired(now)"]
B --> C{"key already\nin Map?"}
C -- "yes (before fix)" --> D["rows.set(key, …)\n(key stays at original position)"]
C -- "yes (after fix)" --> E["rows.delete(key)\nrows.set(key, …)\n(key moves to tail = newest)"]
C -- "no" --> F["rows.set(key, …)"]
E --> G["evictCapacity()"]
F --> G
D --> G
G --> H{"rows.size >\nCAPACITY?"}
H -- yes --> I["delete oldest entry\n(first in insertion order)"]
I --> H
H -- no --> J["done"]
Reviews (2): Last reviewed commit: "test(sdk): document cache defaults in te..." | Re-trigger Greptile |
Summary
Mirrors the Greptile follow-up from upstream PR RhysSullivan#1118 into fork
dev.devalready has the richer cache primitive surface, including SDK cache config, API scoped service lookup, Cloudflare KV support, hostCACHEwiring, and later cache consumers. This PR intentionally ports only the remaining behavior drift: refreshing fallback cache insertion order when writing an existing key, plus the focused regression tests from RhysSullivan#1118.Changes
set, so Map insertion order reflects the newest write.executor-cache.test.tscoverage for default fallback cache get, remove, TTL expiry, size cleanup, and LRU write refresh behavior.Intentional Differences From Upstream RhysSullivan#1118
devalready has them.devalready has them.Tests
bun run --cwd packages/core/sdk test -- src/executor-cache.test.tsbun run --cwd packages/core/sdk typecheckbunx oxlint -c .oxlintrc.jsonc --deny-warnings packages/core/sdk/src/executor.ts packages/core/sdk/src/executor-cache.test.tsgit diff --check