@@ -36,9 +36,9 @@ class CacheManager {
3636 } ) ;
3737 }
3838
39- // Debounced function to update local storage with all caches
40- updateStorage ( ) {
41- if ( ! this . timeoutId ) {
39+ // Function to update local storage with all caches
40+ updateStorage ( debounced ) {
41+ if ( debounced && ! this . timeoutId ) {
4242 this . timeoutId = setTimeout ( ( ) => {
4343 this . timeoutId = null ;
4444 const cacheDataToStore = { } ;
@@ -49,6 +49,15 @@ class CacheManager {
4949
5050 Storage . setToLocalStore ( this . storageKey , cacheDataToStore ) ;
5151 } , this . debounceDelay ) ;
52+ } else {
53+ // Immediate update without debounce
54+ const cacheDataToStore = { } ;
55+
56+ Object . keys ( this . caches ) . forEach ( ( cacheName ) => {
57+ cacheDataToStore [ cacheName ] = Object . fromEntries ( this . caches [ cacheName ] ) ;
58+ } ) ;
59+
60+ Storage . setToLocalStore ( this . storageKey , cacheDataToStore ) ;
5261 }
5362 }
5463
@@ -58,7 +67,7 @@ class CacheManager {
5867 this . caches [ cacheName ] . clear ( ) ;
5968 } ) ;
6069
61- this . updateStorage ( ) ;
70+ this . updateStorage ( false ) ;
6271 }
6372
6473 // Function to check if the URL is in a specific cache and still valid
@@ -74,7 +83,7 @@ class CacheManager {
7483 return true ; // Cache is valid, URL is allowed
7584 } else {
7685 cache . delete ( normalizedUrl ) ; // Cache expired, remove entry
77- this . updateStorage ( ) ;
86+ this . updateStorage ( true ) ;
7887 }
7988 }
8089 } catch ( error ) {
@@ -95,7 +104,7 @@ class CacheManager {
95104 return true ; // Cache is valid, string is allowed
96105 } else {
97106 cache . delete ( string ) ; // Cache expired, remove entry
98- this . updateStorage ( ) ;
107+ this . updateStorage ( true ) ;
99108 }
100109 }
101110 } catch ( error ) {
@@ -113,7 +122,7 @@ class CacheManager {
113122
114123 // Clean expired entries and update storage
115124 if ( this . cleanExpiredEntries ( ) === 0 ) {
116- this . updateStorage ( ) ;
125+ this . updateStorage ( true ) ;
117126 }
118127
119128 if ( cacheName === "all" ) {
@@ -145,7 +154,7 @@ class CacheManager {
145154
146155 // Clean expired entries and update storage
147156 if ( this . cleanExpiredEntries ( ) === 0 ) {
148- this . updateStorage ( ) ;
157+ this . updateStorage ( true ) ;
149158 }
150159
151160 if ( cacheName === "all" ) {
@@ -192,7 +201,7 @@ class CacheManager {
192201
193202 if ( entriesRemoved > 0 ) {
194203 console . debug ( `Removed ${ entriesRemoved } expired entries from caches.` ) ;
195- this . updateStorage ( ) ;
204+ this . updateStorage ( true ) ;
196205 }
197206 return entriesRemoved ;
198207 }
0 commit comments