Refresh & Invalidate
refresh() forces a reload ignoring fresh cache; invalidate() marks data stale so the next get() reloads.
Basic usage
typescript
const loader = new AsyncLoader(fn, { cache: 60_000, hash: "data" });
await loader.get();
await loader.refresh(); // force reload now, returns the new result (aborts any inflight load)
loader.invalidate(); // mark stale; the next get() reloads
await loader.get(); // reloadsMethod comparison
| Method | Behavior | Loads immediately? | Works without cache? |
|---|---|---|---|
refresh(args?) | Clears the cache and reloads immediately; aborts any inflight load first. Returns the new result | ✅ Yes | ✅ Yes |
invalidate() | Clears the cache entry and resets a completed signal, so the next get() reloads | ❌ No (triggered by the next get()) | ✅ Yes |
clear() | Clears the current instance's cache entry | ❌ No | ❌ Only meaningful with a cache |
invalidate's advantage
Unlike clear(), invalidate() also works without a cache (cache=0) — because it resets the completed signal, causing the next get() to reload.