Skip to content

docs/sdk: getCachedEntry cache-first loader example never revalidates stale entries #1461

Description

@rickylabs

Version

@netscript/sdk@0.0.5 published docs and implementation.

Problem

The published service SDK example says:

const entry = await api.orders.list.getCachedEntry({ limit: 20 });
if (entry) return entry; // serve cached; SDK reloads stale in the background

That comment is false for 0.0.5. actionMethod.getCachedEntry() delegates directly to the provider, and CacheQuery#getCachedEntry() only reads the store and converts its timestamp. It does not evaluate staleTime, call queryFn, or schedule revalidation. A loader following the documented fast path can therefore serve stale data until cacheTime expiry (300 seconds by default).

Minimal reproduction

const cache = new CacheQuery(memoryStore);
let calls = 0;
await cache.query(['orders', 'list', '{}'], {
  staleTime: 1,
  cacheTime: 60_000,
  queryFn: async () => ({ value: ++calls }),
});
await new Promise((resolve) => setTimeout(resolve, 5));
const stale = await cache.getCachedEntry<{ value: number }>(['orders', 'list', '{}']);
await Promise.resolve();
console.log(stale?.data.value); // 1
console.log(calls);             // 1: no foreground/background refresh

Related: the current background revalidation path bypasses the inflight-request map, so concurrent stale SWR readers can also duplicate refreshes.

Expected

Either correct the documentation to require a cache-aware query() before reading metadata, or add a queryEntry()/revalidating-entry API that applies the declared stale policy while returning { data, cachedAt }.

Acceptance

  • Fresh entries cause zero upstream calls.
  • Missing entries fetch once and return a current timestamp.
  • Stale entries follow the documented blocking or SWR policy.
  • Concurrent stale readers issue exactly one refresh.
  • cachedAt reflects the refreshed value.
  • The published loader example has an executable regression proving stale data eventually refreshes.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions