Performance: Cache middleware pattern
HIGH IMPACT
This pattern affects server response time and reduces client wait by serving cached content quickly.
const cache = {};
app.get('/data', (req, res, next) => {
if (cache.data) {
return res.json(cache.data);
}
next();
}, (req, res) => {
const data = fetchFromDatabase();
cache.data = data;
res.json(data);
});app.get('/data', (req, res) => {
const data = fetchFromDatabase();
res.json(data);
});| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No cache middleware | N/A (server-side) | N/A | High due to slow response delaying LCP | [X] Bad |
| Cache middleware serving cached data | N/A | N/A | Low, fast response improves LCP | [OK] Good |