Quickstart

Quickstart: Cache the product catalogue correctly

The catalogue changes rarely, so caching it removes the API from your hot path and keeps you well under the rate limit. This recipe shows the exact code, uses only the unauthenticated public ring, and links out to the endpoints and the application flow so the reader always has a next step.

2 min read

Cache-ControlRespect the header
SWRServe stale, refresh behind
fallbackNever blank on error

Honour the header

Read Cache-Control: max-age on the response and cache for exactly that long. Do not invent your own TTL that ignores what the API tells you.

resp = requests.get(f'{BASE}/products', timeout=10)
max_age = parse_max_age(resp.headers.get('Cache-Control', ''))
cache.set('products', resp.json()['data'], ttl=max_age or 3600)

Stale-while-revalidate

Serve the cached copy immediately and refresh in the background when it is near expiry. The reader never waits on the API, and a transient failure just serves slightly older data — far better than an error.

Fallback on cold miss

If the cache is empty and the fetch fails, render a static link to business loans rather than an empty grid.

Frequently asked questions

What TTL should I use?

Whatever Cache-Control advertises. If the header is absent, an hour is a safe default for reference data like the catalogue.

Should I cache in the browser or the server?

Both are valid. Server-side caching protects the API best; edge or browser caching adds speed. A Worker or CDN in front is ideal.

Funding for UK limited companies

Credicorp lends to your company, not to you personally — short-term working capital with no personal guarantee. See what your business could access.