You've already forked pigallery2
							
							
				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:
		
							
								
								
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "pigallery2", | ||||
|   "version": "1.8.6", | ||||
|   "version": "1.8.7", | ||||
|   "lockfileVersion": 1, | ||||
|   "requires": true, | ||||
|   "dependencies": { | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user