1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Clearing cache on reload #285

It should help with reducing the confusion as forced reload did not cleared local cache.
This commit is contained in:
Patrik J. Braun 2021-05-15 09:51:19 +02:00
parent 951dbbf066
commit ea3506c388
2 changed files with 13 additions and 1 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "pigallery2", "name": "pigallery2",
"version": "1.8.6", "version": "1.8.7",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -14,6 +14,7 @@ interface CacheItem<T> {
item: T; item: T;
} }
@Injectable() @Injectable()
export class GalleryCacheService { export class GalleryCacheService {
@ -25,6 +26,12 @@ export class GalleryCacheService {
private static readonly VERSION = 'version'; private static readonly VERSION = 'version';
constructor(private versionService: VersionService) { constructor(private versionService: VersionService) {
// if it was a forced reload not a navigation, clear cache
if (GalleryCacheService.wasAReload()) {
GalleryCacheService.deleteCache();
}
const onNewVersion = (ver: string) => { const onNewVersion = (ver: string) => {
if (ver !== null && if (ver !== null &&
localStorage.getItem(GalleryCacheService.VERSION) !== ver) { localStorage.getItem(GalleryCacheService.VERSION) !== ver) {
@ -36,6 +43,11 @@ export class GalleryCacheService {
onNewVersion(this.versionService.version.value); onNewVersion(this.versionService.version.value);
} }
private static wasAReload(): boolean {
const perfEntries = performance.getEntriesByType('navigation') as PerformanceNavigationTiming [];
return perfEntries && perfEntries[0] && perfEntries[0].type === 'reload';
}
private static loadCacheItem(key: string): SearchResultDTO { private static loadCacheItem(key: string): SearchResultDTO {
const tmp = localStorage.getItem(key); const tmp = localStorage.getItem(key);
if (tmp != null) { if (tmp != null) {