API reference

cache

Cache GET responses in memory.

Enable caching

ts
const api = createClient({  baseUrl: "https://api.example.com",  cache: { ttl: 60_000, max: 500 },});

Options

  • ttlDefault 30000
    number
    Milliseconds an entry stays fresh.
  • maxDefault 100
    number
    Entries kept before the least recently used is evicted.
  • keyDefault url.href
    (url: URL) => string
    Builds the cache key for a request.
OptionTypeDefault
ttl
Milliseconds an entry stays fresh.
number30000
max
Entries kept before the least recently used is evicted.
number100
key
Builds the cache key for a request.
(url: URL) => stringurl.href

Invalidation

Call api.cache.delete(path) after a write, or api.cache.clear() to drop everything.

Was this page helpful?

Updated