feat: 重构胶囊缓存逻辑,增加设置和移除缓存的方法

This commit is contained in:
kuaifan 2025-11-03 01:29:34 +08:00
parent b445af932c
commit 1c8b73a381

View File

@ -322,18 +322,7 @@ export default {
capsule: config, capsule: config,
} }
}) })
;(async () => { this.setCapsuleCache(name, config)
const cache = await $A.IDBJson("microAppsCapsuleCache");
if ($A.isTrue(config.no_cache)) {
if (typeof cache[name] === "undefined") {
return
}
delete cache[name];
} else {
cache[name] = config;
}
await $A.IDBSet("microAppsCapsuleCache", cache);
})()
}, },
nextZIndex: () => { nextZIndex: () => {
if (typeof window.modalTransferIndex === 'number') { if (typeof window.modalTransferIndex === 'number') {
@ -366,6 +355,37 @@ export default {
} }
}, },
/**
* 设置胶囊缓存
* @param name
* @param config
*/
async setCapsuleCache(name, config) {
const cache = await $A.IDBJson("microAppsCapsuleCache");
if ($A.isTrue(config.no_cache)) {
if (typeof cache[name] === "undefined") {
return
}
delete cache[name];
} else {
cache[name] = config;
}
await $A.IDBSet("microAppsCapsuleCache", cache);
},
/**
* 移除胶囊缓存
* @param name
*/
async removeCapsuleCache(name) {
const cache = await $A.IDBJson("microAppsCapsuleCache");
if (typeof cache[name] === "undefined") {
return
}
delete cache[name];
await $A.IDBSet("microAppsCapsuleCache", cache);
},
/** /**
* 观察打开微应用 * 观察打开微应用
* @param config * @param config
@ -374,10 +394,12 @@ export default {
// //
this.backupConfigs[config.name] = $A.cloneJSON(config); this.backupConfigs[config.name] = $A.cloneJSON(config);
// //
if (!$A.isHave(config.capsule, true)) { const capsuleCache = await $A.IDBJson("microAppsCapsuleCache");
const capsuleCache = await $A.IDBJson("microAppsCapsuleCache"); if ($A.isJson(capsuleCache[config.name])) {
if ($A.isJson(capsuleCache[config.name])) { if ($A.isHave(config.capsule, true)) {
Object.assign(config.capsule, capsuleCache[config.name]);
} else {
config.capsule = capsuleCache[config.name]; config.capsule = capsuleCache[config.name];
} }
} }
@ -648,10 +670,12 @@ export default {
break; break;
case "restart": case "restart":
this.removeCapsuleCache(name)
this.onRestartApp(name) this.onRestartApp(name)
break; break;
case "destroy": case "destroy":
this.removeCapsuleCache(name)
this.closeMicroApp(name, true) this.closeMicroApp(name, true)
break; break;