Skip to content

Instantly share code, notes, and snippets.

@PavlikPolivka
Created December 1, 2021 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PavlikPolivka/afc62671dbaa59102df9cfb7fbc3b983 to your computer and use it in GitHub Desktop.
Save PavlikPolivka/afc62671dbaa59102df9cfb7fbc3b983 to your computer and use it in GitHub Desktop.
if (_cacheValues.has(key)) {
return Promise.resolve(_cacheValues.get(key));
} else if (_cachePromises.has(key)) {
return _cachePromises.get(key);
} else {
const promise = new Promise(function (resolve, reject) {
return getData(key).then(data => {
_cacheValues.set(key, data);
_cachePromises.delete(key);
const now = new Date().getTime();
_cacheResolvedTime.set(key, now);
resolve(data);
});
});
_cachePromises.set(key, promise);
return promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment