// frontend/utils/handlers/preloadHandler.js // preload 缓存 handler(简单型,但跨用户清理 + invalidateAll) // 跨用户:删除所有 preload:xxx:* 不依赖 currentUid // 内存清理:由 cacheManager.cleanCategory 触发 invalidateAll const PREFIX = 'preload:' function listAllPreloadKeys() { try { const info = uni.getStorageInfoSync() return (info.keys || []).filter((k) => k.startsWith(PREFIX)) } catch (e) { return [] } } export default { id: 'preload', label: '预加载数据缓存', description: '列表页提前拉取的数据', warning: false, async computeSize() { const keys = listAllPreloadKeys() let bytes = 0 for (const k of keys) { try { const v = uni.getStorageSync(k); if (v != null) bytes += JSON.stringify(v).length } catch (e) {} } return { sizeBytes: bytes, keyCount: keys.length } }, async clean() { const keys = listAllPreloadKeys() let freed = 0 let count = 0 for (const k of keys) { let valueBytes = 0 try { const v = uni.getStorageSync(k) if (v != null) valueBytes = JSON.stringify(v).length } catch (e) { console.warn('[preloadHandler] read failed:', k, e.message) continue } try { uni.removeStorageSync(k) freed += valueBytes count++ } catch (e) { console.warn('[preloadHandler] remove failed:', k, e.message) } } return { freedBytes: freed, keyCount: count } }, }