Problem Statement
What are common caching strategies used in Node.js?
Explanation
Common strategies include in-memory cache (Node-cache), distributed cache (Redis), and HTTP-level caching using ETags or Cache-Control headers. Caching reduces repeated database hits and speeds up response times.
Code Solution
SolutionRead Only
const cache=new Map();
function getUser(id){
if(cache.has(id)) return cache.get(id);
const user=db.find(id);
cache.set(id,user);
return user;
}