Performance: In-memory caching with node-cache
MEDIUM IMPACT
This concept affects server response time and reduces backend processing load, improving how fast pages or data are served to users.
import NodeCache from 'node-cache'; const cache = new NodeCache({ stdTTL: 60 }); app.get('/data', (req, res) => { const cachedData = cache.get('data'); if (cachedData) { return res.json(cachedData); } fetchFromDatabase().then(data => { cache.set('data', data); res.json(data); }); });
app.get('/data', async (req, res) => { const data = await fetchFromDatabase(); res.json(data); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching - fetch on every request | N/A (server-side) | N/A | N/A | [X] Bad |
| In-memory caching with node-cache | N/A (server-side) | N/A | N/A | [OK] Good |