Cache
import { Cache } from "@hyper-fetch/core"
Description
Cache class handles the data exchange with the dispatchers.
Defined in cache/cache.ts:23
Parameters
Properties
events
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 }
Methods
clear()
clear()
Preview
clear()
Description
Clear cache storages
Defined in cache/cache.ts:237
Return
Promise<void>
delete()
delete()
Preview
delete(cacheKey)
Description
Delete record from storages and trigger revalidation
Defined in cache/cache.ts:124
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
void
get()
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
Name | Details |
---|---|
cacheKey
|
|
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()
getLazyKeys()
Preview
getLazyKeys()
Description
Used to receive keys from sync storage and lazy storage
Defined in cache/cache.ts:192
Return
Promise<string[]>
getLazyResource()
getLazyResource()
Preview
getLazyResource<Response, Error, AdapterType>(cacheKey)
Description
Used to receive data from lazy storage
Defined in cache/cache.ts:157
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
Promise<CacheValueType<Response, Error, AdapterType>>
keys()
keys()
Preview
keys()
Description
Get sync storage keys, lazyStorage keys will not be included
Defined in cache/cache.ts:114
Return
string[]
revalidate()
revalidate()
Preview
revalidate(cacheKey)
Description
Revalidate cache by cacheKey or partial matching with RegExp
Defined in cache/cache.ts:135
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
Promise<void>
scheduleGarbageCollector()
scheduleGarbageCollector()
Preview
scheduleGarbageCollector(cacheKey)
Description
Schedule garbage collection for given key
Defined in cache/cache.ts:205
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
Promise<void>
set()
set()
Preview
set<Response, Error>(request, response)
Description
Set the cache data to the storage
Defined in cache/cache.ts:61
Parameters
Name | Details |
---|---|
request
|
|
response
|
|
Return
void