Caching
How to cache CoworkingView API responses: ETag, If-None-Match, 304 and the advisory lifetime of each endpoint.
Catalogue data changes slowly, so caching is the best thing you can do for your app's speed and for staying inside the rate limit.
What the API sends
Every successful GET carries:
ETag: a weak validator of the body (it looks likeW/"…").Cache-Control:public, max-age=N, stale-while-revalidate=M(orno-storefor the few endpoints that must never be reused).
max-age is how long a copy is fresh. stale-while-revalidate is how long beyond that you may keep serving the old copy while you fetch a new one in the background.
Revalidate with If-None-Match
When a copy is no longer fresh, don't download it again blindly. Send the ETag you stored back in If-None-Match:
- 1.GET /v1/facets?locale=en
- 2.200 · body · ETag: W/"abc" · max-age=600
- 3.Store body + ETag
- 4.GET … · If-None-Match: W/"abc"
- 5.304 Not Modified · no body
- 6.Keep using the stored body
curl -i "https://api.coworkingview.com/v1/facets?locale=en" -H 'If-None-Match: W/"abc"'On 304 the response has no body: keep using the copy you stored, and update its freshness from the new Cache-Control. A 200 means the data changed: replace your copy and its ETag.
How long each endpoint can be reused
These are the advisory lifetimes the API sends today. Always read the real Cache-Control header, as the values can be tuned.
| Endpoints | max-age | stale-while-revalidate |
|---|---|---|
/v1/properties, /v1/properties/map, /v1/properties/{slug}, /v1/search/suggest | 5 minutes | 1 hour |
/v1/facets, /v1/market/rates, /v1/operators/{slug}, /v1/places/{kind}/{slug} | 10 minutes | 1 hour |
/v1/geo/bootstrap (countries, cities, zones) | 1 hour | 1 day |
/v1/health, and the POST lead endpoints | never cached (no-store) | none |
/v1/geo/bootstrap changes rarely and is small: fetch it once at start-up and keep it.
Good habits
- Key your cache by the full URL, including the query string: the same path with another
localeor filter is another resource. - Don't cache error responses for long. A
429or a502is a moment, not a fact. - The
meta.citation.accesseddate tells you when the data was served; show it if you display figures. - If you run a server, put a shared cache in front of the API: many of your users then cost us one request.