清除缓存新增批量清楚
This commit is contained in:
parent
b8dcd6d572
commit
0a2e4647e8
@ -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()
|
||||||
routeParamsCache.remove(view.path)
|
setTimeout(() => {
|
||||||
|
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() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { pa } from 'element-plus/es/locale';
|
import { pa } from 'element-plus/es/locale';
|
||||||
import { reactive } from 'vue';
|
import { reactive } from 'vue';
|
||||||
// import type { String } from 'vue-router';
|
// import type { String } from 'vue-router';
|
||||||
|
|
||||||
export type QueryParams = {
|
export type QueryParams = {
|
||||||
pageNo: number;
|
pageNo: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@ -41,11 +41,11 @@ const saveCache = (cache: Map<string, CachedParams>) => {
|
|||||||
);
|
);
|
||||||
sessionStorage.setItem(ROUTE_PARAMS_CACHE_KEY, JSON.stringify(serializable));
|
sessionStorage.setItem(ROUTE_PARAMS_CACHE_KEY, JSON.stringify(serializable));
|
||||||
};
|
};
|
||||||
|
|
||||||
const initCache = (): Map<string, CachedParams> => {
|
const initCache = (): Map<string, CachedParams> => {
|
||||||
const cached = sessionStorage.getItem(ROUTE_PARAMS_CACHE_KEY);
|
const cached = sessionStorage.getItem(ROUTE_PARAMS_CACHE_KEY);
|
||||||
if (!cached) return new Map();
|
if (!cached) return new Map();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(cached);
|
const parsed = JSON.parse(cached);
|
||||||
return new Map(
|
return new Map(
|
||||||
@ -73,9 +73,8 @@ 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) {
|
||||||
const path = getCacheKey(route);
|
const path = getCacheKey(route);
|
||||||
return this.cache.get(path)?.queryParams; // 简化返回
|
return this.cache.get(path)?.queryParams; // 简化返回
|
||||||
@ -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(
|
||||||
@ -106,4 +115,4 @@ const routeParamsCache = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default routeParamsCache;
|
export default routeParamsCache;
|
||||||
|
Loading…
Reference in New Issue
Block a user