2 min read
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.
Related reading

Quickstart: Build a product comparison table
Rendering a comparison table straight from GET /public/v1/products gives readers an always-current view of…
Read →
Quickstart: handle rate limits on the public API
The public ring is rate-limited, and a 429 tells you exactly when to try again. Read the RateLimit-Remaining…
Read →
Quickstart: use the Credicorp public API in Cloudflare Workers
Here is the idiomatic way to call the Credicorp public API from Cloudflare Workers. Fetch the product…
Read →
Quickstart: list Credicorp business-finance products
GET /public/v1/products returns the live catalogue of Credicorp business-finance products. Each item carries…
Read →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.