Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created December 4, 2023 16:01
Show Gist options
  • Save suhailgupta03/e54a0d8de083479f4698251474130497 to your computer and use it in GitHub Desktop.
Save suhailgupta03/e54a0d8de083479f4698251474130497 to your computer and use it in GitHub Desktop.
let cache = {}; // just a simple js object
// cache is just some space in RAM (memory)
function getStudentDetailsFromDatabase(name) { // AWS - US east
return {
name: `${name} is a student`,
age: Math.floor(Math.random() * 100)
} // response time is n seconds
}
function main(name) {
if(cache[name]) {
console.log("pulling from cache :", name);
return cache[name];
}else {
cache[name] = getStudentDetailsFromDatabase(name);
return cache[name];
}
}
main("suhail")
main("adity")
main("aditya")
main("swain")
main("adity")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment