Skip to main content
Version: 3.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

client

Required

C

options

Optional

CacheOptionsType<ClientInstance>

Properties

clearKey

Description

Defined in cache/cache.ts:29

Type

string

client

Description

Defined in cache/cache.ts:33

Type

C

emitter

Description

Defined in cache/cache.ts:24

Type

EventEmitter

events

Description

Defined in cache/cache.ts:25

Type

{ emitCacheData: <Response,Error,AdapterType>(cacheKey: string, data: CacheValueType<Response, Error, AdapterType>) => void; emitRevalidation: (cacheKey: string) => void; onData: <Response,Error,AdapterType>(cacheKey: string, callback: (data: CacheValueType<Response, Error, AdapterType>) => 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<ClientInstance>

storage

Description

Defined in cache/cache.ts:27

Type

CacheStorageType

Methods

clear()

Preview

clear()

Description

Clear cache storages

Defined in cache/cache.ts:237

Return

Promise<void>

delete()

Preview

delete(cacheKey)

Description

Delete record from storages and trigger revalidation

Defined in cache/cache.ts:124

Parameters

NameDetails

cacheKey

Required

string

Return

void

get()

Preview

get<Response, Error, AdapterType>(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:102

Parameters

NameDetails

cacheKey

Required

string

Return

{
additionalData: T extends BaseAdapterType<any, any, any, infer A, any> ? A : never | null;
data: GenericDataType | null;
error: GenericErrorType | null;
isSuccess: boolean;
status: T extends BaseAdapterType<any, any, infer S, any, any> ? S : never | null;
isCanceled: boolean;
isOffline: boolean;
retries: number;
timestamp: number;
cacheTime: number;
clearKey: string;
garbageCollection: number;
}

getLazyKeys()

Preview

getLazyKeys()

Description

Used to receive keys from sync storage and lazy storage

Defined in cache/cache.ts:192

Return

Promise<string[]>

getLazyResource()

Preview

getLazyResource<Response, Error, AdapterType>(cacheKey)

Description

Used to receive data from lazy storage

Defined in cache/cache.ts:157

Parameters

NameDetails

cacheKey

Required

string

Return

Promise<CacheValueType<Response, Error, AdapterType>>

keys()

Preview

keys()

Description

Get sync storage keys, lazyStorage keys will not be included

Defined in cache/cache.ts:114

Return

string[]

revalidate()

Preview

revalidate(cacheKey)

Description

Revalidate cache by cacheKey or partial matching with RegExp

Defined in cache/cache.ts:135

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:205

Parameters

NameDetails

cacheKey

Required

string

Return

Promise<void>

set()

Preview

set<Response, Error>(request, response)

Description

Set the cache data to the storage

Defined in cache/cache.ts:61

Parameters

NameDetails

request

Required

RequestInstance | RequestJSON<RequestInstance, unknown, QueryParamsType, null>

response

Required

ResponseReturnType<Response, Error, ExtractAdapterTypeFromClient<C>> & ResponseDetailsType

Return

void