feat: cache resources
This commit is contained in:
parent
6a791b4dc6
commit
cc95512f39
|
@ -10,9 +10,17 @@ export class Resource {
|
|||
}
|
||||
|
||||
static read(uri) {
|
||||
if (!this.loadCache) {
|
||||
this.loadCache = {};
|
||||
}
|
||||
if (this.loadCache[uri]) {
|
||||
return Promise.resolve(JSON.parse(JSON.stringify(this.loadCache[uri])));
|
||||
}
|
||||
if ('undefined' !== typeof window) {
|
||||
return fetch(uri).then((response) => {
|
||||
return response.json();
|
||||
}).then((json) => {
|
||||
return this.loadCache[uri] = json;
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
@ -24,7 +32,7 @@ export class Resource {
|
|||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
resolve(JSON.parse(buffer.toString('utf8')));
|
||||
resolve(this.loadCache[uri] = JSON.parse(buffer.toString('utf8')));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user