Created
December 4, 2023 16:01
-
-
Save suhailgupta03/e54a0d8de083479f4698251474130497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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