@@ -31,13 +31,13 @@ function log(...args) {
31
31
const kCONTENTS_VERSION = 5 ;
32
32
33
33
let mActivated = false ;
34
+ const mCaches = { } ;
34
35
35
36
export function activate ( ) {
36
37
mActivated = true ;
37
38
configs . $addObserver ( onConfigChange ) ;
38
39
39
- if ( ! configs . persistCachedTree &&
40
- browser . storage . session ) {
40
+ if ( ! configs . persistCachedTree ) {
41
41
browser . windows . getAll ( ) . then ( windows => {
42
42
for ( const win of windows ) {
43
43
browser . sessions . removeWindowValue ( win . id , Constants . kWINDOW_STATE_CACHED_TABS ) . catch ( ApiTabs . createErrorSuppressor ( ) ) ;
@@ -299,17 +299,13 @@ async function updateWindowCache(owner, key, value) {
299
299
if ( ! owner )
300
300
return ;
301
301
302
- if ( ! configs . persistCachedTree &&
303
- browser . storage . session ) {
302
+ if ( ! configs . persistCachedTree ) {
304
303
const storageKey = `backgroundCache-${ await UniqueId . ensureWindowId ( owner . windowId ) } -${ key } ` ;
305
- if ( value ) {
306
- const data = { } ;
307
- data [ storageKey ] = value ;
308
- return browser . storage . session . set ( data ) ;
309
- }
310
- else {
311
- return browser . storage . session . remove ( storageKey ) ;
312
- }
304
+ if ( value )
305
+ mCaches [ storageKey ] = value ;
306
+ else
307
+ delete mCaches [ storageKey ] ;
308
+ return ;
313
309
}
314
310
315
311
if ( value === undefined ) {
@@ -345,11 +341,7 @@ export function markWindowCacheDirtyFromTab(tab, akey) {
345
341
async function getWindowCache ( owner , key ) {
346
342
if ( ! configs . persistCachedTree ) {
347
343
const storageKey = `backgroundCache-${ await UniqueId . ensureWindowId ( owner . windowId ) } -${ key } ` ;
348
- const defaultData = { } ;
349
- defaultData [ storageKey ] = undefined ;
350
- return browser . storage . session . get ( defaultData ) . then ( data => {
351
- return data [ storageKey ] ;
352
- } ) ;
344
+ return mCaches [ storageKey ] ;
353
345
}
354
346
return browser . sessions . getWindowValue ( owner . windowId , key ) . catch ( ApiTabs . createErrorHandler ( ) ) ;
355
347
}
@@ -525,6 +517,14 @@ Tab.onHidden.addListener(tab => {
525
517
reserveToCacheTree ( tab . windowId ) ;
526
518
} ) ;
527
519
520
+ browser . windows . onRemoved . addListener ( async windowId => {
521
+ const storageKeyPrefix = `backgroundCache-${ await UniqueId . ensureWindowId ( windowId ) } -` ;
522
+ for ( const key in mCaches ) {
523
+ if ( key . startsWith ( storageKeyPrefix ) )
524
+ delete mCaches [ key ] ;
525
+ }
526
+ } ) ;
527
+
528
528
function onConfigChange ( key ) {
529
529
switch ( key ) {
530
530
case 'useCachedTree' :
0 commit comments