fetchData() is asynchronous and returns a Promise. What is the main issue?
medium
A. fetchData() blocks the server, causing timeout
B. cache.info is never set, causing infinite loop
C. res.send() cannot send strings
D. res.send() is called before fetchData() resolves, sending a Promise object
Solution
Step 1: Identify async function usage
fetchData() returns a Promise but code treats it as synchronous.
Step 2: Understand res.send() timing
res.send(data) runs immediately, sending the unresolved Promise, not actual data.
Final Answer:
res.send() is called before fetchData() resolves, sending a Promise object -> Option D
Quick Check:
Async function needs await before sending [OK]
Hint: Await async calls before sending response [OK]
Common Mistakes:
Ignoring async nature of fetchData()
Assuming cache is never set
Thinking res.send() can't send strings
5. You want to cache user profile data in Express but ensure it updates every 10 minutes. Which approach best balances caching and data freshness?
hard
A. Store data in cache with a timestamp; refresh cache if older than 10 minutes
B. Cache data forever without expiration to maximize speed
C. Never cache user data to always get fresh info
D. Clear cache manually only when server restarts
Solution
Step 1: Understand caching with expiration
To keep data fresh, cache should have a time limit after which it refreshes.
Step 2: Evaluate options for freshness and speed
Store data in cache with a timestamp; refresh cache if older than 10 minutes uses timestamp to refresh cache every 10 minutes, balancing speed and freshness.
Final Answer:
Store data in cache with a timestamp; refresh cache if older than 10 minutes -> Option A
Quick Check:
Timed cache refresh = Store data in cache with a timestamp; refresh cache if older than 10 minutes [OK]
Hint: Use timestamps to refresh cache periodically [OK]
Common Mistakes:
Caching forever causes stale data
Never caching loses speed benefits
Manual cache clearing is unreliable
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.