client/api: cache API requests
Specifically, cache all GET requests until first POST/PUT/DELETE request.
This commit is contained in:
parent
256a4e49b9
commit
543d0fca57
|
@ -10,21 +10,33 @@ class Api {
|
||||||
this.user = null;
|
this.user = null;
|
||||||
this.userName = null;
|
this.userName = null;
|
||||||
this.userPassword = null;
|
this.userPassword = null;
|
||||||
|
this.cache = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
get(url) {
|
get(url) {
|
||||||
return this._process(url, request.get);
|
if (url in this.cache) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
resolve(this.cache[url]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this._process(url, request.get).then(response => {
|
||||||
|
this.cache[url] = response;
|
||||||
|
return Promise.resolve(response);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
post(url, data, files) {
|
post(url, data, files) {
|
||||||
|
this.cache = {};
|
||||||
return this._process(url, request.post, data, files);
|
return this._process(url, request.post, data, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
put(url, data, files) {
|
put(url, data, files) {
|
||||||
|
this.cache = {};
|
||||||
return this._process(url, request.put, data, files);
|
return this._process(url, request.put, data, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(url) {
|
delete(url) {
|
||||||
|
this.cache = {};
|
||||||
return this._process(url, request.delete);
|
return this._process(url, request.delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue