mwg API
    Preparing search index...

    Class TrackCache

    A least-recently-used cache of loaded tracks under a BusBudgetPolicy. A load in flight is shared by everyone who asks for the same key, a failure or a null answer is not remembered so the next request retries, and a track that is currently playing survives its own eviction because the Channel holds the buffer, so evicting only means the next request decodes again.

    import { TrackCache, type LoadedTrack } from '@datamoc/mwg/audio';

    declare function decode(path: string): Promise<LoadedTrack>;

    const cache = new TrackCache({ maxMegabytes: 64 });
    const track = await cache.load('music/town.mid', () => decode('music/town.mid'));
    console.log(cache.stats().bytes, track?.buffer.duration);
    Index
    • forgets one track; returns whether it was cached

      Parameters

      • key: string

      Returns boolean