mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 10:14:26 +08:00
clear legacy runtime cache when clearing the application code cache
This commit is contained in:
+44
-22
@@ -212,38 +212,60 @@ export function updateMapCacheExpiration(expireSeconds: number): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearApplicationCodeCache(): Promise<void> {
|
export function clearCaches(cacheNames: string[], cacheNamePrefixes?: string[]): Promise<void> {
|
||||||
if (!window.caches) {
|
if (!window.caches) {
|
||||||
logger.error('caches API is not supported in this browser');
|
logger.error('caches API is not supported in this browser');
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
return window.caches.delete(SW_CODE_CACHE_NAME).then(success => {
|
return new Promise((resolve, reject) => {
|
||||||
if (success) {
|
const promises = [];
|
||||||
logger.info(`cache "${SW_CODE_CACHE_NAME}" cleared successfully`);
|
|
||||||
} else {
|
for (const cacheName of cacheNames) {
|
||||||
logger.warn(`failed to clear cache "${SW_CODE_CACHE_NAME}"`);
|
promises.push(window.caches.delete(cacheName).then(success => {
|
||||||
|
if (success) {
|
||||||
|
logger.info(`cache "${cacheName}" cleared successfully`);
|
||||||
|
return Promise.resolve(cacheName);
|
||||||
|
} else {
|
||||||
|
logger.warn(`failed to clear cache "${cacheName}"`);
|
||||||
|
return Promise.reject(cacheName);
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
|
||||||
logger.error(`failed to clear cache "${SW_CODE_CACHE_NAME}"`, error);
|
if (cacheNamePrefixes) {
|
||||||
|
for (const prefix of cacheNamePrefixes) {
|
||||||
|
promises.push(findFirstCacheName(prefix).then(cacheName => {
|
||||||
|
return window.caches.delete(cacheName).then(success => {
|
||||||
|
if (success) {
|
||||||
|
logger.info(`cache "${cacheName}" cleared successfully`);
|
||||||
|
return Promise.resolve(cacheName);
|
||||||
|
} else {
|
||||||
|
logger.warn(`failed to clear cache "${cacheName}"`);
|
||||||
|
return Promise.reject(cacheName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(error => {
|
||||||
|
logger.warn(`cache with prefix "${prefix}" not found`, error);
|
||||||
|
return Promise.resolve();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
|
resolve();
|
||||||
|
}).catch(() => {
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearMapDataCache(): Promise<void> {
|
export function clearApplicationCodeCache(): Promise<void> {
|
||||||
if (!window.caches) {
|
return clearCaches([SW_CODE_CACHE_NAME], [SW_RUNTIME_CACHE_NAME_PREFIX]);
|
||||||
logger.error('caches API is not supported in this browser');
|
}
|
||||||
return Promise.reject();
|
|
||||||
}
|
|
||||||
|
|
||||||
return window.caches.delete(SW_MAP_CACHE_NAME).then(success => {
|
export function clearMapDataCache(): Promise<void> {
|
||||||
if (success) {
|
return clearCaches([SW_MAP_CACHE_NAME]);
|
||||||
logger.info(`cache "${SW_MAP_CACHE_NAME}" cleared successfully`);
|
|
||||||
} else {
|
|
||||||
logger.warn(`failed to clear cache "${SW_MAP_CACHE_NAME}"`);
|
|
||||||
}
|
|
||||||
}).catch(error => {
|
|
||||||
logger.error(`failed to clear cache "${SW_MAP_CACHE_NAME}"`, error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearAllBrowserCaches(): Promise<void> {
|
export function clearAllBrowserCaches(): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user