1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-10-30 23:57:43 +02: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",
"version": "1.8.6",
"version": "1.8.7",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -14,6 +14,7 @@ interface CacheItem<T> {
item: T;
}
@Injectable()
export class GalleryCacheService {
@@ -25,6 +26,12 @@ export class GalleryCacheService {
private static readonly VERSION = 'version';
constructor(private versionService: VersionService) {
// if it was a forced reload not a navigation, clear cache
if (GalleryCacheService.wasAReload()) {
GalleryCacheService.deleteCache();
}
const onNewVersion = (ver: string) => {
if (ver !== null &&
localStorage.getItem(GalleryCacheService.VERSION) !== ver) {
@@ -36,6 +43,11 @@ export class GalleryCacheService {
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 {
const tmp = localStorage.getItem(key);
if (tmp != null) {