Cache
import { Cache } from "@hyper-fetch/core"
Description
Cache class handles the data exchange with the dispatchers.
Defined in cache/cache.ts:25
Parameters
Properties
events
events
Description
Defined in cache/cache.ts:27
Type
{ emitCacheData: <Response,Error,Adapter>(cacheKey: string, data: CacheValueType<Response, Error, Adapter>) => void; emitInvalidation: (cacheKey: string) => void; onData: <Response,Error,Adapter>(cacheKey: string, callback: (data: CacheValueType<Response, Error, Adapter>) => void) => VoidFunction; onInvalidate: (cacheKey: string, callback: () => void) => VoidFunction }
Methods
clear()
clear()
Preview
clear()
Description
Clear cache storages
Defined in cache/cache.ts:274
Return
Promise<void>
delete()
delete()
Preview
delete(cacheKey)
Description
Delete record from storages and trigger invalidation event
Defined in cache/cache.ts:161
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
void
get()
get()
Preview
get<Response, Error, Adapter>(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:139
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
{
data: GenericDataType | null;
error: GenericErrorType | null;
extra: T extends AdapterType<any, any, any, infer A, any> ? A : never | null;
status: T extends AdapterType<any, any, infer S, any, any> ? S : never | null;
success: boolean;
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:229
Return
Promise<string[]>
getLazyResource()
getLazyResource()
Preview
getLazyResource<Response, Error, Adapter>(cacheKey)
Description
Used to receive data from lazy storage
Defined in cache/cache.ts:194
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
Promise<CacheValueType<Response, Error, Adapter>>
invalidate()
invalidate()
Preview
invalidate(cacheKey)
Description
Invalidate cache by cacheKey or partial matching with RegExp
Defined in cache/cache.ts:172
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
Promise<void>
keys()
keys()
Preview
keys()
Description
Get sync storage keys, lazyStorage keys will not be included
Defined in cache/cache.ts:151
Return
string[]
scheduleGarbageCollector()
scheduleGarbageCollector()
Preview
scheduleGarbageCollector(cacheKey)
Description
Schedule garbage collection for given key
Defined in cache/cache.ts:242
Parameters
Name | Details |
---|---|
cacheKey
|
|
Return
Promise<void>
set()
set()
Preview
set<Request>(request, response)
Description
Set the cache data to the storage
Defined in cache/cache.ts:62
Parameters
Name | Details |
---|---|
request
|
|
response
|
|
Return
void
update()
update()
Preview
update<Request>(request, partialResponse)
Description
Update the cache data with partial response data
Defined in cache/cache.ts:111
Parameters
Name | Details |
---|---|
request
|
|
partialResponse
|
|
Return
void