2 lines
1.3 KiB
JavaScript
2 lines
1.3 KiB
JavaScript
"use strict";const e=require("../common/vendor.js");exports.cleanExpiredCache=function(){try{const o=e.index.getStorageSync("video_cache_info")||{},n=Date.now();let c=0;return Object.keys(o).forEach((t=>{const a=o[t];n-a.time>2592e6&&(console.log("[CacheManager] 清理过期缓存:",a.url),e.index.removeSavedFile({filePath:a.path,success:()=>{console.log("[CacheManager] 文件已删除:",a.path)}}),e.index.removeStorageSync(t),delete o[t],c++)})),c>0&&(e.index.setStorageSync("video_cache_info",o),console.log(`[CacheManager] 已清理 ${c} 个过期缓存`)),c}catch(o){return console.error("[CacheManager] 清理缓存失败:",o),0}},exports.cleanOldestCache=function(){try{const o=e.index.getStorageSync("video_cache_info")||{},n=Object.keys(o).map((e=>({key:e,...o[e]})));if(n.length<=50)return 0;n.sort(((e,o)=>e.time-o.time));const c=n.length-50;let t=0;for(let a=0;a<c;a++){const c=n[a];console.log("[CacheManager] 清理旧缓存:",c.url),e.index.removeSavedFile({filePath:c.path,success:()=>{console.log("[CacheManager] 文件已删除:",c.path)}}),e.index.removeStorageSync(c.key),delete o[c.key],t++}return t>0&&(e.index.setStorageSync("video_cache_info",o),console.log(`[CacheManager] 已清理 ${t} 个旧缓存`)),t}catch(o){return console.error("[CacheManager] 清理缓存失败:",o),0}};
|