export async function cachedLoras({read,write,live,fresh=false}) { const cached=read() || {image:[],video:[]}; if (!fresh && (cached.image?.length || cached.video?.length)) return cached; try { const listed=await live(); const image=Array.isArray(listed?.image)?listed.image:[]; const video=Array.isArray(listed?.video)?listed.video:[]; // Comfy asleep / empty: keep disk. Otherwise replace — never merge stale names that freeze adds. if (!image.length && !video.length) return cached; const next={image,video}; write(next); return next; } catch { return cached; } }