清除缓存新增批量清楚

This commit is contained in:
Ledo 2025-08-21 14:58:20 +08:00
parent b8dcd6d572
commit 0a2e4647e8
2 changed files with 23 additions and 9 deletions

View File

@ -60,18 +60,23 @@ export const useTagsViewStore = defineStore('tagsView', {
delView(view: RouteLocationNormalizedLoaded) { delView(view: RouteLocationNormalizedLoaded) {
this.delVisitedView(view) this.delVisitedView(view)
this.delCachedView() this.delCachedView()
setTimeout(() => {
routeParamsCache.remove(view.path) routeParamsCache.remove(view.path)
}, 300)
}, },
// 删除tag // 删除tag
delVisitedView(view: RouteLocationNormalizedLoaded) { delVisitedView(view: RouteLocationNormalizedLoaded) {
const list = [];
for (const [i, v] of this.visitedViews.entries()) { for (const [i, v] of this.visitedViews.entries()) {
if (v.path === view.path) { if (v.path === view.path) {
this.visitedViews.splice(i, 1) this.visitedViews.splice(i, 1)
routeParamsCache.remove(view.path) list.push(view.path);
break break
} }
} }
setTimeout(() => {
routeParamsCache.removeBatch(list)
}, 300)
}, },
// 删除缓存 // 删除缓存
delCachedView() { delCachedView() {

View File

@ -73,7 +73,6 @@ const routeParamsCache = {
timestamp: Date.now(), timestamp: Date.now(),
}; };
this.cache.set(path, cachedParams); this.cache.set(path, cachedParams);
saveCache(this.cache);
}, },
get(route: String) { get(route: String) {
@ -90,7 +89,17 @@ const routeParamsCache = {
} }
return false; return false;
}, },
removeBatch(routeArrary: []) {
routeArrary.forEach(route =>{
const path = getCacheKey(route);
if (this.cache.has(path)) {
this.cache.delete(path);
saveCache(this.cache);
}
})
},
cleanExpired(expireHours = DEFAULT_EXPIRE_HOURS) { cleanExpired(expireHours = DEFAULT_EXPIRE_HOURS) {
const now = Date.now(); const now = Date.now();
const expired = Array.from(this.cache.entries()).filter( const expired = Array.from(this.cache.entries()).filter(