Skip to main content
The SDK automatically caches requests to minimize API calls and improve performance.

Request deduplication

When multiple components request the same data, the SDK automatically deduplicates requests:
const collection1 = client.collection({ handle: 'shirts' })
const collection2 = client.collection({ handle: 'shirts' })

await Promise.all([
  collection1.execute(),
  collection2.execute(),
])

// Only ONE network request is made

Local storage restoration

Cached results are restored from local storage on back navigation:
// Initial page load
const collection = client.collection({ handle: 'shirts' })
await collection.execute() // Makes API call, caches result

// User navigates away and returns via back button
// Cache is restored from localStorage - no API call needed
Disable auto-restore if needed:
const { data: client } = createClient({
  token: 'your-token',
  sorts: [{ name: 'Featured', code: 'featured' }],
  facets: [{ name: 'Color', code: 'options.color' }],
  restoreCache: false,
})

Cache invalidation

Invalidate cached queries by pattern:
const { cache } = client

// Invalidate all browse queries
cache.invalidate('browse')

// Invalidate specific search
cache.invalidate('search:ring')

// Clear all cache
cache.clear()

Search cache

The prepare endpoint caches expensive operations (embeddings, query expansions):
const search = client.search()

await search.prepare({ query: 'ring' })

// Multiple executes reuse the prepare cache
await search.execute({ query: 'ring', page: 1 })
await search.execute({ query: 'ring', page: 2 })
When using search_id, the server maintains the cache for 15 minutes:
const prepareResult = await search.prepare({ query: 'ring' })
const searchId = prepareResult.data?.searchId

await search.execute({ 
  query: 'ring',
  searchId,
})

Next steps

Performance

Learn performance optimization techniques.

Best Practices

Review SDK best practices and common pitfalls.