Class CachableSource<T>

The source of a 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 ReadableStream(
new CachableSource<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 source = new CachableSource<number>(
cache,
['numbers'],
() => ++i
)

const stream = new ReadableStream(source)

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

source.clear()
// 2

Type Parameters

  • T

Implements

Constructors

Properties

#abortController: AbortController = ...
#cache: StorageCache
#ms: number
#path: string[]
#pullResult: CachePuller<T>
#sourceHasFinished: boolean = false

Accessors

Methods

Generated using TypeDoc