Skip to content

Cache

Cache: object

Defined in: Core/Cache.ts:34

make: <K, E, V, SerializedKey>(config) => Cache<K, E, V> = makeCache

Creates a cache around a keyed load.

K

E

V

SerializedKey = K

Config<K, E, V, SerializedKey>

Cache<K, E, V>

Cache for the freshness, single-flight, and eviction policies.

const priceList = Cache.make({
  load: (sku: string) => Task.Result.tryCatch(() => catalog.price(sku), { onError: toPriceError })(),
  ttl: Duration.minutes(10),
  staleWhileRevalidate: Duration.minutes(2),
  maxSize: 1_000,
});

const price = await priceList.load("SKU-1042");
const known = priceList.peek("SKU-1042");