voxolith

openModelCacheControls()

Open controls for the model cache in IndexedDB database name (the name given to serveGenerators({ cache })), or null where there is no IndexedDB. Works from the main thread while workers use the cache.

function openModelCacheControls(name: string): Promise<ModelCacheControls | null>;

Defined in: engine/src/worker/cache.ts:486

These are controls, never automatic: the engine clears or trims nothing unless asked (apart from a worker dropping an older build's entries, and a maxBytes cap if the worker was given one). On phones storage is small and the browser may evict a whole origin under pressure. Two platform calls help an app decide, and both are the app's to make: navigator.storage.estimate() reports the origin's usage and quota (compare it with usage()), and navigator.storage.persist() asks the browser not to evict the origin (it may prompt the user or refuse; ask after the user has shown they will come back, not on first load).

Parameters

ParameterType
namestring

Returns

Promise<ModelCacheControls | null>

Example

const cache = await openModelCacheControls("voxolith-models");
if (cache) {
  const { entries, bytes } = await cache.usage();
  const { quota = Infinity } = (await navigator.storage?.estimate()) ?? {};
  console.log(`${entries} models, ${(bytes / 1e6).toFixed(1)} MB`);
  if (bytes > quota / 4) await cache.trim(quota / 8);
  await cache.clear({ generator: "voxolith/tree.broadleaf" });
  cache.close();
}

On this page