Cache gets (#3437)

* Cache gets

* Added test
This commit is contained in:
Andrew Henry
2020-10-08 20:30:23 -07:00
committed by GitHub
parent b637307de6
commit f3d593bc1e
2 changed files with 26 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ define([
this.providers = {};
this.rootRegistry = new RootRegistry();
this.rootProvider = new RootObjectProvider.default(this.rootRegistry);
this.cache = {};
}
/**
@@ -154,6 +155,11 @@ define([
* has been saved, or be rejected if it cannot be saved
*/
ObjectAPI.prototype.get = function (identifier) {
let keystring = this.makeKeyString(identifier);
if (this.cache[keystring] !== undefined) {
return this.cache[keystring];
}
identifier = utils.parseKeyString(identifier);
const provider = this.getProvider(identifier);
@@ -165,7 +171,15 @@ define([
throw new Error('Provider does not support get!');
}
return provider.get(identifier);
let objectPromise = provider.get(identifier);
this.cache[keystring] = objectPromise;
return objectPromise.then(result => {
delete this.cache[keystring];
return result;
});
};
ObjectAPI.prototype.delete = function () {