Skip to main content
Version: 1.x.x

Cache


import { Cache } from "@hyper-fetch/core"

Description

Cache class handles the data exchange with the dispatchers.

Defined in cache/cache.ts:23

Parameters

NameDetails

builder

Required

BuilderInstance

options

Optional

CacheOptionsType

Properties

builder

Description

Defined in cache/cache.ts:33

Type

BuilderInstance

clearKey

Description

Defined in cache/cache.ts:29

Type

string

emitter

Description

Defined in cache/cache.ts:24

Type

EventEmitter

events

Description

Defined in cache/cache.ts:25

Type

{ emitCacheData: <Response,Error>(cacheKey: string, data: CacheValueType<Response, Error>) => void; emitRevalidation: (cacheKey: string) => void; onData: <Response,Error>(cacheKey: string, callback: (data: CacheValueType<Response, Error>) => void) => VoidFunction; onRevalidate: (cacheKey: string, callback: () => void) => VoidFunction }

garbageCollectors

Description

Defined in cache/cache.ts:30

Type

Map<string, Timeout>

lazyStorage

Description

Defined in cache/cache.ts:28

Type

CacheAsyncStorageType

options

Description

Defined in cache/cache.ts:33

Type

CacheOptionsType

storage

Description

Defined in cache/cache.ts:27

Type

CacheStorageType

Methods

clear()

Preview

clear()

Description

Clear cache storages

Defined in cache/cache.ts:228

Return

Promise<void>

delete()

Preview

delete(cacheKey)

Description

Delete record from storages and trigger revalidation

Defined in cache/cache.ts:119

Parameters

NameDetails

cacheKey

Required

string

Return

void

get()

Preview

get<Response, Error>(cacheKey)

Description

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

Defined in cache/cache.ts:99

Parameters

NameDetails

cacheKey

Required

string

Return

{
cacheTime: number;
clearKey: string;
data: [GenericDataType | null, GenericErrorType | null, number | null];
details: {
isCanceled: boolean;
isFailed: boolean;
isOffline: boolean;
retries: number;
timestamp: number;
};
garbageCollection: number;
}

getLazyKeys()

Preview

getLazyKeys()

Description

Used to receive keys from sync storage and lazy storage

Defined in cache/cache.ts:185

Return

Promise<string[]>

getLazyResource()

Preview

getLazyResource<Response, Error>(cacheKey)

Description

Used to receive data from lazy storage

Defined in cache/cache.ts:152

Parameters

NameDetails

cacheKey

Required

string

Return

Promise<CacheValueType<Response, Error>>

keys()

Preview

keys()

Description

Get sync storage keys, lazyStorage keys will not be included

Defined in cache/cache.ts:109

Return

string[]

revalidate()

Preview

revalidate(cacheKey)

Description

Revalidate cache by cacheKey or partial matching with RegExp

Defined in cache/cache.ts:130

Parameters

NameDetails

cacheKey

Required

string | RegExp

Return

Promise<void>

scheduleGarbageCollector()

Preview

scheduleGarbageCollector(cacheKey)

Description

Schedule garbage collection for given key

Defined in cache/cache.ts:198

Parameters

NameDetails

cacheKey

Required

string

Return

Promise<void>

set()

Preview

set<Response, Error>(command, response, details)

Description

Set the cache data to the storage

Defined in cache/cache.ts:61

Parameters

NameDetails

command

Required

CommandInstance | CommandDump<CommandInstance, unknown, ClientQueryParamsType, null>

response

Required

ClientResponseType<Response, Error>

details

Required

CommandResponseDetails

Return

void