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
| Parameter | Type |
|---|---|
name | string |
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();
}openModelCache()
The model cache in IndexedDB database name, or null where there is none (bun, some private windows, a database an older build in another tab holds open). Used by serveGenerators in the worker; entries stored under any other salt are deleted when it opens, so a new build frees the old build's models.
openModelCacheOn()
openModelCache on a store of your own: deletes the entries of every other salt, then returns makeModelCache on it.