Class CachableStream<T>

An extension to the ReadableStream that queues items only when a timed cache becomes invalid.

See

Example

Caching for 30 minutes.

const cache = new StorageCache(
localStorage,
'my-cache',
30 * 60_000
)

let i = 0
const stream = new CachableStream<number>(
cache,
['numbers'],
() => ++i
)

stream.pipeTo(write(console.info))
// 1

await setTimeout(30 * 60_000))
// 2

Example

Manually clearing cache.

const cache = new StorageCache(
localStorage,
'my-cache',
30 * 60_000
)

let i = 0
const stream = new CachableStream<number>(
cache,
['numbers'],
() => ++i
)

stream.pipeTo(write(console.info))
// 1

stream.clear()
// 2

Type Parameters

  • T

Hierarchy

  • ReadableStream<T>
    • CachableStream

Implements

Constructors

Properties

#source: CachableSource<T>
locked: boolean

Accessors

Methods

  • Parameters

    • Optional reason: any

    Returns Promise<void>

  • Parameters

    • options: {
          mode: "byob";
      }
      • mode: "byob"

    Returns ReadableStreamBYOBReader

  • Returns ReadableStreamDefaultReader<T>

  • Parameters

    • Optional options: ReadableStreamGetReaderOptions

    Returns ReadableStreamReader<T>

  • Type Parameters

    • T

    Parameters

    • transform: ReadableWritablePair<T, T>
    • Optional options: StreamPipeOptions

    Returns ReadableStream<T>

  • Parameters

    • destination: WritableStream<T>
    • Optional options: StreamPipeOptions

    Returns Promise<void>

  • Returns [ReadableStream<T>, ReadableStream<T>]

Generated using TypeDoc