Performance: Cache invalidation strategies
HIGH IMPACT
Cache invalidation strategies affect how quickly updated content is served, impacting page load speed and user experience.
app.get('/data', (req, res) => { const data = getDataFromDb(); res.set('Cache-Control', 'no-cache'); // forces revalidation res.json(data); });
app.get('/data', (req, res) => { res.set('Cache-Control', 'max-age=86400'); // cache for 1 day res.json(getDataFromDb()); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Long max-age without invalidation | Minimal | 0 | Low initially, high on update delay | [X] Bad |
| No-cache header forcing revalidation | Minimal | 0 | Moderate due to revalidation | [!] OK |
| Static ETag header | Minimal | 0 | Low initially, high stale risk | [X] Bad |
| Dynamic ETag with 304 responses | Minimal | 0 | Low, efficient network usage | [OK] Good |
| Cache with no invalidation on update | Minimal | 0 | Low initially, high stale risk | [X] Bad |
| Cache invalidated on data update | Minimal | 0 | Low, fresh content | [OK] Good |