When your code depends on data that is 'far away', in other words expensive to obtain, it's common to utilize a cache.. However it is notoriously common to find code that depends on a cache to a certain boilerplate ugly block of code, whose looks and behavior are actually more insidious than at first glance. I'll explain through examples why this is a problem and how to write it cleaner.
Imagine you're in the future - where the only fuel your spaceship can use is Unobtainium.
You get this fuel, Unobtainium, by calling a function, which takes some time to return. Now the return value from this function will be a delayed value, so we implement it as a Promise slightly delayed, for a randomly determined amount, which is then turned into an object like the following: