js-bao-wss-client / CacheFacade
Interface: CacheFacade
The client's key-value cache surface, exposed as client.cache. Provides cache-key generation, cached fetches (both arbitrary async work and HTTP requests), cache-entry metadata, and cache clearing. Several sub-APIs (e.g. client.me.get()) use it internally for offline-first reads.
Properties
clear
clear: (
key) =>Promise<void>
Removes a single entry from the cache by key.
Parameters
key
string
The cache key to remove
Returns
Promise<void>
clearAll
clearAll: () =>
Promise<void>
Removes all entries from the cache.
Returns
Promise<void>
fetchCached
fetchCached: <
T>(keyOrParts,fetcher,options?) =>Promise<T|null>
Returns a cached value if available, otherwise calls the fetcher and caches the result.
Type Parameters
T
T
Parameters
keyOrParts
string | unknown[]
A cache key string or an array of parts to build a key from
fetcher
() => Promise<T>
Async function that produces the value when the cache misses
options?
Controls cache freshness, network behavior, and timeout
Returns
Promise<T | null>
fetchHttp
fetchHttp: <
T>(req,options?) =>Promise<T|null>
Fetches data from an HTTP endpoint with automatic caching based on request parameters.
Type Parameters
T
T
Parameters
req
body?
unknown
Request body, included in cache key for non-GET requests
keyBase?
string
Custom base string for the cache key instead of the auto-generated one
method
string
HTTP method (e.g., "GET", "POST")
path
string
API endpoint path
query?
Record<string, unknown>
Query parameters appended to the request URL
options?
Controls cache freshness, network behavior, and timeout
Returns
Promise<T | null>
info
info: (
key) =>Promise<{ageMs?:number;updatedAt?:string; }>
Returns metadata about a cache entry, including its age and last update time.
Parameters
key
string
The cache key to look up
Returns
Promise<{ ageMs?: number; updatedAt?: string; }>
key
key: (
base,params?) =>string
Generates a deterministic cache key from a base string and optional parameters.
Parameters
base
string
The base string for the cache key (e.g., an endpoint name)
params?
unknown
Optional parameters that are hashed into the key for uniqueness
Returns
string