`title: OPFS 垃圾回收与引用计数实践``categories: Web 开发/前端/数据管理``keywords: OPFS,垃圾回收,引用计数,索引,清理``description: 为 OPFS 文件建立引用计数与索引,定期清理无引用与过期文件,降低占用并提升可控性。`引用计数模型IndexedDB 维护 `files(id,name,refCount,lastUsed)`;业务引用增减时更新计数与时间。清理实现async function cleanupUnused(thresholdMs = 30 * 24 * 3600 * 1000) { // 查询 refCount==0 且 lastUsed 早于阈值的文件,调用 root.removeEntry(name) }

发表评论 取消回复