Skip to main content
The SDK caches controller responses in an in-memory LRU to minimize API calls and improve performance. The cache lasts for the life of the page. Optional storage persists prepared search IDs, not controller responses, so a later page can reuse the prepare step.

Request deduplication

When multiple controllers request the same data, the SDK deduplicates in-flight requests and reuses cached results:

Cache configuration

Control cache behavior with the cache option at SDK initialization:
The SDK does not select a storage backend automatically. Pass storage: localStorage, storage: sessionStorage, or a custom backend when you need prepared search IDs to survive navigation.

Storage backends

A storage backend is any object matching a subset of the Storage interface:

Browser storage

Node.js (memory store)

For SSR or build scripts, pass an in-memory store:

sessionStorage

Use sessionStorage when you want prepared search IDs scoped to the current tab. The SDK still keeps controller responses in memory only:

Cache invalidation

The SDK does not expose a public cache invalidation API. To clear cached data, reset the SDK singleton or dispose individual controllers:
For the most common case, changing controller parameters (for example, a new page or filter) naturally produces a new cache key.

Search cache

The search controller uses the prepare endpoint to cache expensive work. get() automatically prepares the query when needed and retries a 425 response until results are ready.
The prepare() call returns { search_id } for observability. Reuse is automatic within the page from memory, and across pages when you configure storage. Prepared search ID entries expire after five minutes by default.

Custom fetch

The SDK uses the global fetch by default. Provide a custom implementation via the fetch option for SSR runtimes, testing, or environments where fetch is unavailable or blocked:

xhrFetch (browser fallback)

xhrFetch is an XMLHttpRequest-based fetch shipped with the SDK. Use it when ad blockers, browser extensions, or restrictive network policies intercept fetch calls:

Custom fetch

You can pass any function matching the FetchFn signature. Common uses:
  • SSR / Node: inject a Node-compatible fetch on older runtimes.
  • Testing: stub responses without intercepting global fetch.
  • Instrumentation: add tracing or auth headers around the request.
The SDK handles abort signals and error classification on top of whatever fetch returns. Your adapter only needs to issue the request and return a Response.

Next steps

Performance

Learn performance optimization techniques.

Best practices

Review SDK best practices and common pitfalls.