Component caching

Some components are expensive: they wait for slow APIs or crunch numbers. If their output is the same for many visitors, render them once and keep the HTML for a while.

<Cached> renders its children to a string with jsxToString, stores the markup under a key and inserts it with html() on later requests. The report below takes about a second to render. Reload the page: the first request renders it, the following ones get the cached copy for 30 seconds. Switch the region to start over.

Reload
Render time1,000 ms🐢 Freshly rendered
Cached copy expires in 30 s

Sales Americas · 2026

Units sold
11,785
Best month
Dec
Growth
+188 %
  1. Jan
  2. Feb
  3. Mar
  4. Apr
  5. May
  6. Jun
  7. Jul
  8. Aug
  9. Sep
  10. Oct
  11. Nov
  12. Dec

Rendered at 10:26:54 UTC

How it works

<Cached cacheKey={`report:${region}`}>
  <Report region={region} />
</Cached>

To cache data instead of markup (e.g. an API response used by several components), see the cache helper used by GitHub repos.