cacophony
    Preparing search index...

    Class AudioCache

    AudioCache provides efficient caching of audio resources using HTTP caching standards.

    Features:

    • Three-layer caching: Memory (LRU) → Browser Cache API → Network
    • HTTP conditional requests with ETag and Last-Modified support
    • Robust error handling with cache inconsistency recovery

    Caching Strategy:

    • Always makes conditional requests when validation tokens (ETag/Last-Modified) are available
    • Uses TTL as fallback only when no validation tokens exist
    • Conditional requests are lightweight (304 responses have no body)
    const cache = new AudioCache();
    const audioBuffer = await cache.getAudioBuffer(audioContext, 'audio.mp3');

    // Optional: Configure TTL for when no validation tokens exist
    AudioCache.setCacheExpirationTime(60 * 60 * 1000); // 1 hour

    Implements

    • ICache
    Index
    • Returns void

    • Get an AudioBuffer for the specified URL, using intelligent caching strategies.

      Caching Flow:

      1. Check memory cache (LRU) for decoded AudioBuffer
      2. Check persistent cache for raw ArrayBuffer and metadata
      3. Make conditional HTTP request if validation tokens available
      4. Decode audio data and cache at all levels

      The cache prioritizes HTTP conditional requests (ETag/Last-Modified) over TTL to ensure content freshness while maintaining performance through 304 responses.

      Parameters

      • context: BaseContext

        AudioContext for decoding audio data

      • url: string

        URL of the audio resource to fetch

      • Optionalsignal: AbortSignal

        Optional AbortSignal to cancel the operation

      • Optionalcallbacks: CacheCallbacks

      Returns Promise<AudioBuffer>

      Promise that resolves to decoded AudioBuffer

      Error if audio cannot be fetched or decoded

    • Parameters

      • time: number

      Returns void