Skip to main content

Cache

Class


Preview

new Cache(builder, options)

Description

Cache class handles the data exchange with the dispatchers.

Note

Keys used to save the values are created dynamically on the Command class

Import

import { Cache } from "@better-typed/hyper-fetch"

Parameters

Name Type Default Value Description
builder BuilderInstance - -
options CacheOptionsType - -

Methods

set()

Set the cache data to the storage

set<Response, Error>(command, response, details)
Returns a void

Parameters

Name Type Default Value Description
command CommandInstance | CommandDump<CommandInstance, unknown, ClientQueryParamsType, null> - -
response ClientResponseType<Response, Error> - -
details CommandResponseDetails - -

scheduleGarbageCollector()

Schedule garbage collection for given key

scheduleGarbageCollector(cacheKey)
Returns a Promise<void>

Parameters

Name Type Default Value Description
cacheKey string - -

revalidate()

Revalidate cache by cacheKey or partial matching with RegExp

revalidate(cacheKey)
Returns a Promise<void>

Parameters

Name Type Default Value Description
cacheKey string | RegExp -

keys()

Get sync storage keys, lazyStorage keys will not be included

keys()
Returns a string[]

getLazyResource()

Used to receive data from lazy storage

getLazyResource<Response, Error>(cacheKey)

Parameters

Name Type Default Value Description
cacheKey string -

getLazyKeys()

Used to receive keys from sync storage and lazy storage

getLazyKeys()
Returns a Promise<string[]>

get()

Get particular record from storage by cacheKey. It will trigger lazyStorage to emit lazy load event for reading it's data.

get<Response, Error>(cacheKey)

Parameters

Name Type Default Value Description
cacheKey string - -

delete()

Delete record from storages and trigger revalidation

delete(cacheKey)
Returns a void

Parameters

Name Type Default Value Description
cacheKey string -

clear()

Clear cache storages

clear()
Returns a Promise<void>

References