Performance: Caching strategies for cost reduction
HIGH IMPACT
This affects how quickly data is retrieved and how often expensive API calls or computations happen, reducing load time and cost.
cache = {}
async def get_answer(query):
if query in cache:
return cache[query]
response = await call_expensive_api(query)
cache[query] = response
return responseasync def get_answer(query): response = await call_expensive_api(query) return response
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching, repeated API calls | Minimal | Minimal | High due to waiting | [X] Bad |
| In-memory caching of API results | Minimal | Minimal | Low, fast response | [OK] Good |