QueryClient
API Reference for the QueryClient class
QueryClient
The primary interface for interacting with SoulCache.
Import
Constructor
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
config.defaultOptions.staleTime | number | 300000 (5 min) | Time before data is stale |
config.defaultOptions.gcTime | number | 1800000 (30 min) | Time before garbage collection |
config.logger | Logger | undefined | Custom logger implementing { info, warn, error, debug } |
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.
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.