Caching
How long Basker caches FrontStage API responses, what makes a response uncacheable, and how publishing refreshes content
Basker caches successful FrontStage API GET responses at the edge. The full request URL is the cache key, including query, variables, operationName, extensions, and locale. Two visitors who send the same URL share one cached response.
Cache-Control values
| Response | Cache-Control |
|---|---|
Successful GET | public, max-age=60, s-maxage=300, stale-while-revalidate=86400 |
Successful GET that selects ticketing on an event instance | public, max-age=60, s-maxage=60, stale-while-revalidate=86400 |
| Any other response | no-store |
max-age=60: a browser reuses the response for up to 60 seconds.s-maxage: the edge cache reuses the response for up to 300 seconds, or 60 seconds when the query selects ticketing data.stale-while-revalidate=86400: for up to one day afters-maxageends, the edge can serve the old response while it gets a new one.
A response gets no-store when any of these is true:
- The request is a
POST. - The response has an
errorsarray, also when it also hasdata. - The response status is not
200. - The request is a preview request.
- The site is password protected.
- The request has an
Authorizationheader.
Ticketing freshness
Booking status and seat counts change fast. When a query selects the ticketing field of an EventInstance, the whole response uses the 60-second edge lifetime.
To keep the rest of a page on the longer lifetime, put ticketing data in its own query:
query EventPage($slug: String!) {
event(slug: $slug) {
title
description
instances(limit: 20) {
docs { id startDate path }
}
}
}query EventAvailability($eventId: ID!) {
eventInstances(eventId: $eventId, limit: 20) {
docs {
id
ticketing { status label bookingUrl }
}
}
}Publishing
When an editor publishes a change, Basker purges the cached responses that contain the changed content. Other cached responses refresh when their s-maxage ends.
A response that the edge serves during stale-while-revalidate can be up to one refresh behind. Do not depend on a change to show in the API within a fixed time.
Cache in your own app
The edge cache serves every request first. You can also cache in your app:
- Static builds: query at build time and rebuild when content changes.
- Server rendering: let your framework cache each request for about 60 seconds. In Next.js, pass
{ next: { revalidate: 60 } }tofetch. See Build a site with Next.js. - Browsers: the browser cache honors
max-age=60.