fix: 缓存不合法时即刻重置

This commit is contained in:
xream
2024-02-07 01:14:52 +08:00
parent 36377f3c20
commit df0ac8a218
4 changed files with 34 additions and 4 deletions

View File

@@ -10,7 +10,17 @@ class ResourceCache {
if (!$.read(SCRIPT_RESOURCE_CACHE_KEY)) {
$.write('{}', SCRIPT_RESOURCE_CACHE_KEY);
}
this.resourceCache = JSON.parse($.read(SCRIPT_RESOURCE_CACHE_KEY));
try {
this.resourceCache = JSON.parse($.read(SCRIPT_RESOURCE_CACHE_KEY));
} catch (e) {
$.error(
`解析持久化缓存中的 ${SCRIPT_RESOURCE_CACHE_KEY} 失败, 重置为 {}, 错误: ${
e?.message ?? e
}`,
);
this.resourceCache = {};
$.write('{}', SCRIPT_RESOURCE_CACHE_KEY);
}
this._cleanup();
}