QueryClient
API Reference for the QueryClient class
QueryClient
The primary interface for interacting with SoulCache.
Import
Constructor
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
config.defaultOptions.gcTime | number | 1800000 (30 min) | Time before garbage collection |
config.logger | Logger | undefined | Custom logger implementing { info, warn, error, debug } |
Note:
config.defaultOptions.staleTimeis accepted and stamped on cache entries but is not yet used for revalidation decisions in the current public runtime. It will drive stale-time refetching in a future milestone.
Properties
| Property | Type | Description |
|---|---|---|
isDestroyed | boolean | Whether client is destroyed |
queryCount | number | Number of active queries |
Methods
fetchQuery<T>(options)
Fetch data with automatic caching and deduplication.
getQueryData<T>(queryKey)
Read cached data.
getQuerySnapshot<T>(queryKey)
Get the current snapshot for a query (compatible with useSyncExternalStore).
setQueryData<T>(queryKey, updater)
Manually update cache.
subscribe<T>(queryKey, callback)
Subscribe to query updates. Returns an unsubscribe function.
subscribeToQuery(queryKey, listener)
Subscribe to query state changes. Compatible with useSyncExternalStore.
mutate<TData, TVariables>(options)
Execute a mutation.
Note:
retryandretryDelayare accepted and forwarded toMutationCache.create(), butmutate()performs a single attempt. UseMutationEntry.mutateWithRetry()for retrying mutations.
invalidateQueries(queryKey)
Invalidate cache entries by prefix.
removeQuery(queryKey)
Remove a query entry.
clear()
Clear all cache entries.
destroy()
Destroy client and cleanup resources.
getCache()
Access the underlying CacheEngine instance.
getMutationCache()
Access the underlying MutationCache instance.
getScheduler()
Access the underlying Scheduler instance.