import { DIVEResourceKind } from '../prototype/ResourcePrototype.ts'; import { DIVEResourceLease } from '../lease/ResourceLease.ts'; /** * Options of a {@link DIVEResourceCache}. */ export type DIVEResourceCacheOptions = { /** * How many prototypes no lease holds any more are kept for a later draw, * the least recently released one freed first. `0` frees them at once. */ keep?: number; }; /** * Resource prototypes by URL, so a URL is loaded and parsed once however * many resources use it, independent of any DIVE instance or scene. * * Prototypes are keyed by the resolved URL, so relative, `./`-prefixed and * absolute forms of one file share one. Once its last lease is released, a * prototype is kept, up to `keep` of them, and a draw of its URL lends the * loaded data again without loading; a prototype pushed out of that list, or * released while nothing is kept, is freed and dropped, so the next draw of * that URL loads again. A failed load is never kept. * * @typeParam T - The value, e.g. a texture. */ export declare class DIVEResourceCache { private _kind; private _prototypes; /** released prototypes by key, least recently released first */ private _kept; private _keep; /** * @param _kind - How the data is loaded, lent and freed. * @param options - How many released prototypes are kept. */ constructor(_kind: DIVEResourceKind, { keep }?: DIVEResourceCacheOptions); /** * Draws from the prototype of a URL, making it unless it exists. * * @param url - The URL. * @returns The lease, to be released once it is no longer used. */ draw(url: string): Promise>; /** * Frees and drops every kept prototype; prototypes in use stay. */ trim(): void; /** keeps a prototype its last lease left, freeing the oldest kept beyond the limit */ private _idle; /** frees a prototype no lease holds and drops it */ private _free; /** drops a prototype, unless a newer one took its key */ private _drop; }