Caching
When caching is enabled, results with the same hash are reused within the TTL and auto-reloaded after expiry.
Basic usage
typescript
const loader = new AsyncLoader(
(args) => fetch("/api/data", { signal: args.abortSignal }).then((r) => r.json()),
{ cache: 60_000, hash: "data" } // cache for 60 seconds
);
await loader.get(); // first load, writes to cache
await loader.get(); // cache hit, underlying not called
loader.clear(); // clear current instance's cache entry
loader.clearAll(); // clear all cache entries (shared storage)Key points
cacheis the TTL in milliseconds.=0disables caching (default);>0enables it.hashis the cache key. Whencache>0but nohashis provided, an instance-level hash is auto-generated.- Cache hits do not trigger
onPending/onFulfilledcallbacks. - The
storageoption lets you swap the cache backend; the default isMapStorage.
Clearing the cache
| Method | Description |
|---|---|
clear() | Clear the current instance's cache entry |
clearAll() | Clear all cache entries in the shared storage |
vs. invalidation
clear() only makes sense with caching enabled; to mark data stale even without a cache, use invalidate() from Refresh & Invalidate.