Skip to content

EspoCRM – Open Source CRM Application

ref

Yuri Kuznetsov18a91d633d0c
diff --git a/client/src/app.js b/client/src/app.js
index 43f3f4d873..758da993a6 100644
--- a/client/src/app.js
+++ b/client/src/app.js
@@ -332,48 +332,37 @@ class App {
/**
* @private
* @param {module:app~Options} options
- * @return Promise
*/
- initCache(options) {
+ async initCache(options) {
if (!this.useCache) {
- return Promise.resolve();
+ return;
}
- const cacheTimestamp = options.cacheTimestamp || null;
+ const timestamp = options.cacheTimestamp || null;
- this.cache = new Cache(cacheTimestamp);
+ this.cache = new Cache(timestamp);
- const storedCacheTimestamp = this.cache.getCacheTimestamp();
+ const storedTimestamp = this.cache.getCacheTimestamp();
- cacheTimestamp ?
- this.cache.handleActuality(cacheTimestamp) :
+ timestamp ?
+ this.cache.handleActuality(timestamp) :
this.cache.storeTimestamp();
if (!window.caches) {
- return Promise.resolve();
+ return;
}
- return new Promise(resolve => {
- const deleteCache = !cacheTimestamp ||
- !storedCacheTimestamp ||
- cacheTimestamp !== storedCacheTimestamp;
-
- (
- deleteCache ?
- caches.delete('espo') :
- Promise.resolve()
- )
- .then(() => caches.open('espo'))
- .then(cache => {
- this.responseCache = cache;
-
- resolve();
- })
- .catch(() => {
- console.error(`Could not open 'espo' cache.`);
- resolve();
- });
- });
+ const deleteCache = !timestamp || !storedTimestamp || timestamp !== storedTimestamp;
+
+ try {
+ if (deleteCache) {
+ await caches.delete('espo');
+ }
+
+ this.responseCache = await caches.open('espo');
+ } catch (e) {
+ console.error(`Could not open 'espo' cache.`);
+ }
}
/**