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 = sdk.collection({ handle: 'shirts' })
const collection2 = sdk.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 = sdk.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 result = createSdk({
  layersPublicToken: 'token',
  sorts: [{ label: 'Featured', code: 'featured' }],
  facets: ['options.color'],
  restoreFromStorage: false
})

Cache Invalidation

Invalidate cached queries by pattern:
// Invalidate all browse queries
sdk.store.queries.invalidate('browse:*')

// Invalidate specific search
sdk.store.queries.invalidate('search:ring')

// Clear all cache
sdk.store.clear()

Search Cache

The prepare endpoint caches expensive operations (embeddings, query expansions):
const search = sdk.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',
  params: { search_id: searchId }
})

Next Steps