C. getUserFromDb is asynchronous but used synchronously
D. Cache keys are not strings
Solution
Step 1: Check res.send calls in both branches
If cache hit, res.send is called, but code continues and calls res.send again after fetching data.
Step 2: Understand Express response behavior
Calling res.send twice causes an error because response is already sent.
Final Answer:
res.send is called twice causing error -> Option B
Quick Check:
Only one res.send per request allowed [OK]
Hint: Return after sending cached response to avoid double send [OK]
Common Mistakes:
Ignoring multiple res.send calls
Assuming synchronous DB call is fine
Not returning after cache hit
5. You want to optimize response time by streaming a large file in Node.js instead of loading it fully into memory. Which code snippet correctly implements this using Express?