catch caches is not defined
This commit is contained in:
@@ -50,7 +50,11 @@ browser.runtime.onStartup.addListener(async () => {
|
|||||||
// 清除缓存
|
// 清除缓存
|
||||||
const setting = await getSetting();
|
const setting = await getSetting();
|
||||||
if (setting.clearCache) {
|
if (setting.clearCache) {
|
||||||
caches.delete(CACHE_NAME);
|
try {
|
||||||
|
caches.delete(CACHE_NAME);
|
||||||
|
} catch (err) {
|
||||||
|
console.log("[clean caches]", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步订阅规则
|
// 同步订阅规则
|
||||||
|
|||||||
@@ -121,12 +121,12 @@ export const fetchData = async (
|
|||||||
{ useCache, usePool, translator, token, ...init } = {}
|
{ useCache, usePool, translator, token, ...init } = {}
|
||||||
) => {
|
) => {
|
||||||
const cacheReq = await newCacheReq(new Request(input, init));
|
const cacheReq = await newCacheReq(new Request(input, init));
|
||||||
const cache = await caches.open(CACHE_NAME);
|
|
||||||
let res;
|
let res;
|
||||||
|
|
||||||
// 查询缓存
|
// 查询缓存
|
||||||
if (useCache) {
|
if (useCache) {
|
||||||
try {
|
try {
|
||||||
|
const cache = await caches.open(CACHE_NAME);
|
||||||
res = await cache.match(cacheReq);
|
res = await cache.match(cacheReq);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[cache match]", err);
|
console.log("[cache match]", err);
|
||||||
@@ -148,6 +148,7 @@ export const fetchData = async (
|
|||||||
// 插入缓存
|
// 插入缓存
|
||||||
if (useCache) {
|
if (useCache) {
|
||||||
try {
|
try {
|
||||||
|
const cache = await caches.open(CACHE_NAME);
|
||||||
await cache.put(cacheReq, res.clone());
|
await cache.put(cacheReq, res.clone());
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[cache put]", err);
|
console.log("[cache put]", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user