/walkeros:walkeros-using-store-cachefrom walkeros
Adds read-through caching to walkerOS stores, memoizing slow API/Sheets backings, composing multi-tier cache chains, and deduplicating concurrent reads. Covers TTL choice, error policy, and observability counters.
Ships in walkeros. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Flow.Store.cache wraps any store with a read-through, write-through cache
tier. Reads check the cache first, fall through to the backing on miss, and
populate every tier on the unwind. Writes go to the backing first, then to the
cache best-effort.
The wrapping is transparent: a transformer wired to $store.crm does not know
whether reads hit a memory cache, a GCS tier, or the underlying Sheets API.
Core principle: the cache is advisory. Backing is the source of truth. Failed cache operations degrade performance, never correctness.
TTL is owned by the cache layer, not the store. The store persists
structured values; the cache wrapper manages expiry via the per-rule ttl. An
expired entry is treated as a miss and re-fetched from the backing. Caching
works over any structured backing.
A store's byte-native file mode (config.file: true) is for serving raw
assets byte-exact, not for caching. The cache wraps structured stores, so
flow_validate warns when a store sets both file: true and cache. Drop one:
serve bytes with file: true and no cache, or cache a structured store with no
file.
@walkeros/server-store-api reads a third-party API, and its
misses are not cachedThe talk-demo use case. A sessions lookup runs on every event but most events
in a session share the same key.
{
"stores": {
"sessions": {
"package": "@walkeros/server-store-sheets",
"config": {
"credentials": "$secret.SHEETS_CREDENTIALS",
"settings": {
"id": "1AbC...",
"sheet": "Sessions"
}
},
"cache": { "rules": [{ "ttl": 300 }] }
}
},
"transformers": {
"sessionLookup": {
"code": {
"type": "session-lookup",
"push": "$code:async (event, context) => { if (!event.user?.session) return; const session = await context.env.store.get(event.user.session); if (session) return { event: { ...event, data: { ...event.data, session } } }; }"
},
"env": { "store": "$store.sessions" }
}
}
}
walkerOS ships no generic lookup transformer, so the consumer here is an inline
code transformer. Any transformer or destination that reads its env.store
works the same way.
The first lookup hits Sheets and populates the built-in in-memory tier with a 300-second TTL. The next 300 seconds of identical reads hit memory and skip the Sheets API.
Without the cache: 60 events in 60 seconds = 60 Sheets reads, each counted against the Sheets API read quota. With the cache: 60 events in 60 seconds = 1 Sheets read.
Same shape, longer TTL because every read is a network round-trip to the bucket:
{
"stores": {
"users": {
"package": "@walkeros/server-store-gcs",
"config": {
"settings": { "bucket": "my-user-records", "prefix": "users/" }
},
"cache": { "rules": [{ "ttl": 3600 }] }
}
}
}
One-hour TTL is reasonable when user records change rarely. Use flow_validate
to verify the config; the hit rate shows at runtime in the store's counters
(see Observability).
Different keys can have different TTLs. Rules evaluate top-down, first match
wins. The match context is { key, value? }, not event data:
"cache": {
"rules": [
{ "match": { "key": "key", "operator": "prefix", "value": "session:" }, "ttl": 300 },
{ "match": { "key": "key", "operator": "prefix", "value": "user:" }, "ttl": 3600 },
{ "ttl": 60 }
]
}
session:* keys cache for 5 minutesuser:* keys cache for 1 hourA rule without match always matches. Place it last as a fallback.
When the working set exceeds the memory tier's capacity, or cached values should
survive restarts and be shared across instances, add an object storage layer
between memory and the cold backing. The consumer still wires to $store.crm;
the tiers resolve automatically. Use fs, S3, GCS or the built-in memory tier as
a cache tier (a cache.store target). Nothing rejects the Sheets store there,
but every cache read and write then costs a Sheets request.
{
"stores": {
"files": {
"package": "@walkeros/server-store-gcs",
"config": {
"settings": { "bucket": "my-cache-bucket", "prefix": "cache/" }
},
"cache": { "rules": [{ "ttl": 300 }] }
},
"crm": {
"package": "@walkeros/server-store-sheets",
"config": { "settings": { "id": "1AbC...", "sheet": "Customers" } },
"cache": {
"store": "files",
"rules": [{ "ttl": 86400 }]
}
}
},
"transformers": {
"crmLookup": {
"code": {
"type": "crm-lookup",
"push": "$code:async (event, context) => { if (!event.user?.id) return; const crm = await context.env.store.get(event.user.id); if (crm) return { event: { ...event, data: { ...event.data, crm } } }; }"
},
"env": { "store": "$store.crm" }
}
}
}
Lookup chain on crm.get(K):
crm's tier is the files store. The files wrapper checks its own tier
(memory __cache) first, then GCS. HIT, return. A GCS HIT also populates
memory.crm writes to files, which writes GCS and then memory.TTL ordering: shortest at the top (the files memory tier, 300s), longest at
the cold end (the crm entries in GCS, 86400s). Each wrapper checks the expiry
of its own entries, also when a lower tier serves them, so a value is served
stale for at most the longest TTL in the chain (86400s here).
Async-safe by design. Whether your cache store's get is synchronous (the
built-in __cache, an in-memory store) or asynchronous
(@walkeros/server-store-fs, S3, GCS, the cache wrapper itself), the collector
reads through with an await internally. You can mix sync and async stores
freely in a multi-tier chain without any extra configuration; the same HIT/MISS
semantics apply.
Single-flight deduplication is on by default. 50 concurrent
store.get('session:abc') calls on a cold cache produce one backing call,
not 50. All callers receive the same promise.
This is what makes store-level cache useful on a slow backing under high
concurrency. No configuration needed; just set cache on the store.
Verify it works with the inflight_dedups counter (see Observability below).
cache rules cannot do (compared to event cache)Store rules are a stricter subset:
key field. The cache key comes from the caller (store.get(K));
there is no event path to compose.update field. update changes the response a source cache sends; a
store read has no response to change.stop field. Stores always fall through on miss; halting the pipeline
is an event-cache concept.namespace: "" is rejected by the schema (re-introduces the
collision footgun across stores sharing __cache).The schema rejects key, update and stop on a store cache. Use the
event-level Cache when you need them:
key and stop on sources, transformers or destinations, update on a source
cache only.
__cacheOmitting cache.store falls back to the collector's built-in __cache. It is
an in-memory LRU map with:
maxEntries: 10000 (not configurable)Each wrapped store gets an automatic namespace prefix (the store id) so multiple
stores sharing __cache do not collide. Override with cache.namespace: "myns"
if you want explicit control.
At the INFO level the collector logs one line per wrapped store at startup:
INFO [store-cache:sessions] store "sessions" caches with namespace "sessions:" via __cache
wrapped.set(K, V) runs two steps:
backing.set(K, V). If this throws, the wrapper
throws. The cache is not touched.wrapped.delete(K) follows the same shape. A failed cache delete leaves a
poisoned entry that serves stale data until TTL. Both warnings are WARN lines,
which the default log level (ERROR) does not show.
Backing is the source of truth. Code that wraps set / delete should assume
the cache may be lagging.
Read this before relying on the cache for anything correctness-sensitive:
wrapped.set(K, V), a
subsequent wrapped.get(K) in the same process returns V.Pick TTLs accordingly. Short TTLs (1-60s) for mostly-static lookups behind a fast backing; long TTLs (minutes-hours) for cold, expensive lookups where staleness is tolerable.
Each wrapped store exposes counters:
| Counter | Use this to detect |
|---|---|
hits | Cache is actually working |
misses | Working-set size, cold start |
populates | New keys being added to cache |
writes | Set call volume |
deletes | Delete call volume |
inflight_dedups | Concurrent reads on a cold key |
The eviction counters (evictions_entries for the maxEntries cap,
evictions_ttl for expired entries) belong to the built-in tier:
collector.stores.__cache.counters. Each read through a wrapped store also
emits a flow record to the collector's observers (meta.op: "cache",
meta.status hit or miss).
For interactive debugging at runtime:
const { collector } = await startFlow({
/* ... */
});
const sessions = collector.stores.sessions;
if ('counters' in sessions) console.log(sessions.counters);
// { hits: 412, misses: 18, populates: 18, writes: 0, deletes: 0,
// inflight_dedups: 7 }
Healthy cache: hits / (hits + misses) rises over time. inflight_dedups
proves the herd prevention worked.
get(K) that returns undefined from the backing
is not populated. Every subsequent call for a missing key re-hits the backing
until the value exists. Workaround: write a sentinel value on the first miss
and treat it as "not present" in transformer logic.A.cache.store = B and
B.cache.store = A make startFlow reject with
Cycle in cache.store chain: a -> b -> a.destroy, so a store declared with cache never has its destroy
called.cache.store: "X" references break). Migrate explicitly.$code:When a step only needs to read a value out of a store or write one into it, you
do not need to wire $store into the step's env and hand-write a $code:
push. The declarative state block on a source, transformer, or destination
does both directions through the mapping engine. The example uses the sessions
store declared in the first recipe:
"transformers": {
"stashGclid": {
"state": { "mode": "set", "store": "sessions", "key": "event.user.session", "value": "event.data.gclid" }
},
"restoreGclid": {
"state": { "mode": "get", "store": "sessions", "key": "event.user.session", "value": "event.data.gclid" }
}
}
key and value resolve against { event, ingest }, so every path names its
side: event.user.session reads the event, ingest.site reads the pipeline
context a server source lifted from the request. A path without one of these
prefixes never resolves: walkeros validate rejects it and the runtime warns.
key names the store slot and mode sets the direction:
set resolves value (a path, constant, fn, or map) and writes that
payload to the store under key.get reads key from the store and writes the fetched value to the
value path: event.x onto the event, ingest.x into the ingest, where
later steps and route matchers see it but no destination does. For a get,
value must be a string path (or a ValueConfig with key), not a constant
or operator.A store keyed by request context, such as a per-site registry, reads the key from ingest:
"registry": {
"state": { "mode": "get", "store": "registry", "key": "ingest.site", "value": "ingest.tenant" }
}
A transformer runs its get before its own next route, so the route can match
on ingest.tenant. A source runs its state before its next route too, so a
source-level get can feed that route.
To fill several fields from one lookup, add mapping. Its paths are relative to
the value read, and the result merges into the target:
"loadUser": {
"state": {
"mode": "get", "store": "customers", "key": "event.user.id", "value": "event.user",
"mapping": { "map": { "ltv": "ltv", "segment": { "key": "segment", "value": "unknown" } } }
}
}
An object result merges into an object target, anything else replaces it; on a
set the stored entry is read, merged and written back (not atomic). The
mapping runs on a miss too, so only declared fallbacks are written; fn and
condition then receive undefined, while validate receives the resolved
value (a declared fallback, or {} after a map).
Omit store to use the built-in __cache tier; state keys there are prefixed
with state: so they never collide with cache entries. State is fail-open:
a store error is logged and the event passes through unchanged. A store not
declared in flow.stores, or one with file: true, is a validation error
(walkeros validate and deploy preflight). Use state for simple fetch/stash;
reach for $code: only when the logic is genuinely non-declarative.
Full reference: Website: State.
$store. wiring, lifecycleDocumentation:
Flow.Store.cacheSource files:
Cache, StoreCacheRule, EventCacheRule typesWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
walkerOS, store-cache, read-through-cache, memoization, cache-chaining
22 skills in this plugin
/walkeros-create-cmp-sourceUse when creating a new walkerOS CMP (consent management platform) source. Structured fill-in-the-blanks workflow that turns any CMP's consent API into a walkerOS source package. Covers CookieFirst, Usercentrics, CookiePro/OneTrust patterns and generalizes to any CMP./walkeros-create-destinationUse when creating a new walkerOS destination to send events to a vendor or API (GA4/gtag, Meta/Facebook Pixel, Mixpanel, Amplitude, a custom HTTP API, Measurement Protocol), web or server-side. Example-driven workflow: research the vendor SDK and define step examples before implementing the destination interface, env pattern, and mappings./walkeros-create-sourcenpx claudepluginhub elbwalker/walkeros --plugin walkerosOther plugins' skills for the same job