Examples · Data & cache

Shared cache

Two components, one request: cache: true with staleTime.

Both islands ask for /api/stats. With cache: true they share one entry: one request on mount, an instant answer for the second reader, and a background revalidation only once the entry is older than staleTime.

Playground

What to notice

  • Mount both: the Server requests panel shows a single GET.
  • Refresh inside 5 seconds serves from cache; after that the data is stale and refetches while still showing the old value.
  • invalidate() forces every live reader to refetch.

Click “Invalidate” and compare the request count with the two refresh buttons.