Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
What is a major architectural downside of implementing manual caching directly inside your business logic services?
š» Code Challenge | +75 XP
Write the Node.js/Backend code snippet to implement a Node Cache Manual vs Automatic pipeline. Include the setup and basic execution steps.
You are reviewing a Node Cache Manual vs Automatic pipeline and the output is incorrect. Reorder the following pipeline stages in the correct logical order to fix the bug: Input Data, Process, Output.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Applying middleware-level automatic caching to a route that returns per-user data
// Wrong: caches user A's private data and serves it to user B
router.get('/orders/me', cacheMiddleware(300), ordersController);
// Correct: key includes the user, or skip caching entirely for private data
const key = `orders:${req.user.id}`;
const cached = await redis.get(key);The Solution //
A cacheMiddleware keyed only on req.url will cache and replay one user's private data (e.g. their own order history) to every other user who hits the same URL, because the cache key doesn't account for the authenticated user. Automatic URL-based caching is only safe for genuinely public, identical-for-everyone responses ā for per-user data, include the user ID in the cache key or use manual caching with an explicit key.
The Error //
Overriding res.send in middleware but forgetting to preserve the original 'this' binding or status code
// Wrong: caches error responses too
res.send = (body) => { redis.set(req.url, body); originalSend(body); };
// Correct: only cache success responses, preserve context
res.send = function (body) {
if (res.statusCode === 200) redis.set(req.url, body);
return originalSend.call(this, body);
};The Solution //
A naive res.send override that ignores the response status code will happily cache and replay a 500 error response as if it were a successful 200, or lose the original 'this' context and throw at runtime. Only cache successful responses (check res.statusCode before saving) and call the original send with the correct context/arguments preserved.