asset-cache overview
Table of contents
utils
AssetCache (class)
The per-world asset cache behind world.loader: one entry per asset, shared by concurrent and
repeated loads, held by scopes and freed when the last scope holding it is released.
Signature
export declare class AssetCache
has (method)
Signature
public has(key: string): boolean
createScope (method)
Signature
public createScope(): AssetScope
acquire (method)
Returns the asset cached under key for scope to hold, loading it with load when it is not
there. A load that is aborted by the caller that started it is started again for the others
still waiting for it. A caller rejects as soon as its own signal aborts, without waiting for
the load to stop. Rejects with an AbortError once the cache is disposed.
Signature
public async acquire<T>(
key: string,
scope: AssetScope | undefined,
load: (signal: AbortSignal) => Promise<{ value: T; dispose?: () => void }>,
signal?: AbortSignal,
onShared?: () => void,
): Promise<T>
abandon (method)
Signature
private abandon(key: string, entry: Entry): void
remove (method)
Signature
private remove(key: string, entry: Entry): void
dispose (method)
Frees every entry and cancels the loads still running (a load that can't be cancelled frees its result when it finishes). The cache takes no new loads afterwards.
Signature
public dispose(): void
root (property)
Holds every asset loaded without a scope of its own, until the cache is disposed.
Signature
readonly root: AssetScope
AssetScope (class)
A holder of cached assets. Every load made with a scope keeps what it loaded alive for as long as
the scope is; release() lets go of all of it, and whatever no other scope holds is freed.
Created with world.loader.createAssetScope().
Signature
export declare class AssetScope {
constructor(private readonly cache: AssetCache)
}
adopt (method)
Holds everything other holds, independently of it: what other loaded stays cached until
both have let go. For something made from another scope's assets that outlives it.
Signature
public adopt(other: AssetScope): void
release (method)
Lets go of everything loaded with this scope. The scope can't be used afterwards.
Signature
public release(): void