export async function getOrCacheBlob(url: string) {
  const cache = await caches.open("app-sounds-v1");
  const hit = await cache.match(url);
  if (hit) return await hit.blob();

  const res = await fetch(url, { cache: "no-store" });
  if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);

  await cache.put(url, res.clone());
  return await res.blob();
}

export async function evictFromCache(url: string) {
  const cache = await caches.open("app-sounds-v1");
  await cache.delete(url);
}
