Class QueryClient
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
TanStack Query's QueryClient: a cache of query results keyed by QueryKey, shared
by every UseQuery<TQueryFnData, TData>(QueryOptions<TQueryFnData, TData>, QueryClient?) that reaches it. One entry holds one result and at most one
request in flight, whichever component started it, and keeps the result after the components reading
it unmount, until it is collected. A request in flight is kept too when its query function takes no token;
one that does is cancelled when the last component reading the entry leaves, as
QueryFn describes.
public sealed class QueryClient
- Inheritance
-
objectQueryClient
Remarks
Main thread only, like the rest of Velvet. An entry nothing observes is removed once its garbage-collection time has passed on the client's clock, as TanStack Query's timer removes it. The clock is read once a frame, as a retry's wait is, while an entry that can still expire is held: removal lands on the first frame whose reading is at or past the deadline, and an entry whose time has run out reads as absent before then. The loop holds the client weakly, so it is not what keeps a dropped client alive. An entry with a request in flight has not run out, as v5 puts its removal off while it fetches: it runs out a whole garbage-collection time after the request settles, and the clock is read every frame until then.
Constructors
- QueryClient(QueryClientOptions?)
Creates an empty client.
Properties
- DefaultGcTime
The garbage-collection time a query that sets none of its own uses.
- DefaultRefetchOnReconnect
Whether a query that sets none of its own fetches again when the device comes back online.
- DefaultRefetchOnReconnectFn
The function a query that sets none of its own decides whether to fetch again when the device comes back online with; it replaces DefaultRefetchOnReconnect.
- DefaultRefetchOnWindowFocus
Whether a query that sets none of its own fetches again when the application becomes visible.
- DefaultRefetchOnWindowFocusFn
The function a query that sets none of its own decides whether to fetch again when the application becomes visible with; it replaces DefaultRefetchOnWindowFocus.
- DefaultRetry
The number of retries a query that sets none of its own uses.
- DefaultRetryDelay
The retry delay a query that sets none of its own uses.
- DefaultStaleTime
The stale time a query that sets none of its own uses.
Methods
- CancelQueries(QueryFilters?, bool)
Cancels the requests of the entries
filtersselects, TanStack Query'scancelQueries. The token a cancelled query function received is cancelled, and a task a caller awaits for the request, such as FetchQuery<T>(QueryOptions<T, T>)'s, is cancelled with it.
- Clear()
Removes every entry and cancels every request in flight, as TanStack Query's
clear(). A mounted query re-renders without data and fetches into a new entry.
- EnsureQueryData<T>(QueryOptions<T, T>, bool)
The data the entry
optionsnames holds, and otherwise the data a request for it returns, TanStack Query'sensureQueryData.
- FetchQuery<T>(QueryOptions<T, T>)
The data
options' entry holds when it is fresh for the query's stale time, and otherwise the data a request for it returns, TanStack Query'sfetchQuery. A request in flight is joined. The entry is created when there is none and, with nothing reading it, collected after the query's garbage-collection time.
- GetQueriesData<T>(QueryFilters?)
The key and data of each entry
filtersselects that holds data of typeT, TanStack Query'sgetQueriesData. An entry holding another type is left out rather than throwing, since a filter selects across keys.
- GetQueryData<T>(QueryKey)
The data the entry
queryKeynames holds, TanStack Query'sgetQueryData: default when there is no such entry, it has no data yet, or it has gone unread past its garbage-collection time. Placeholder data is never an entry's.
- GetQueryState<T>(QueryKey)
The state of the entry
queryKeynames, TanStack Query'sgetQueryState: null when there is no such entry or it has gone unread past its garbage-collection time.
- InvalidateQueries(QueryFilters?, RefetchOptions?)
InvalidateQueries(QueryKey?) over the entries
filtersselects, TanStack Query'sinvalidateQueries(filters, options). Only entries an enabled query reads are fetched again.
- InvalidateQueries(QueryKey?)
Marks every entry whose key
queryKeymatches stale, and fetches again each one a mounted query is reading — TanStack Query'sinvalidateQueries({ queryKey }), with the partial match of its filter that QueryKey describes. For such an entry, a request already in flight is cancelled and started over when the entry holds data, so a result fetched before the change that invalidated it does not land as current, and joined when the entry is still waiting on its first result. An entry nothing reads is not fetched: a query mounting over it later fetches it, and a request it still has in flight, one whose query function takes no token, is left to land.
- PrefetchQuery<T>(QueryOptions<T, T>)
FetchQuery<T>(QueryOptions<T, T>) without the data: fills the cache ahead of the component that reads it. TanStack Query's
prefetchQuery.
- RefetchQueries(QueryFilters?, RefetchOptions?)
Fetches again the entries
filtersselects that can be: those an enabled query reads, and, for an entry nothing reads, those that were fetched before and keep the options of that fetch. TanStack Query'srefetchQueries.
- RemoveQueries(QueryFilters?)
Removes the entries
filtersselects and cancels their requests, TanStack Query'sremoveQueries. A mounted query reading a removed entry re-renders without data and fetches into a new one, as after Clear().
- ResetQueries(QueryFilters?, RefetchOptions?)
Puts the entries
filtersselects back to the state of one never fetched, with no data and no error, cancelling their requests, and then fetches those an enabled query reads — TanStack Query'sresetQueries. A Type of null refetches the active entries; one that is set also selects what is refetched.
- SetQueriesData<T>(QueryFilters?, Func<T?, T>)
SetQueryData<T>(QueryKey, Func<T?, T>) over each entry
filtersselects that holds data of typeT, TanStack Query'ssetQueriesData. An updater returning null leaves its entry as it was.
- SetQueryData<T>(QueryKey, Func<T?, T>)
SetQueryData<T>(QueryKey, T) with the data
updatermakes of the data the entry holds, default when it holds none, as TanStack Query's functional updater. An updater returning null writes nothing.
- SetQueryData<T>(QueryKey, T)
Writes
datainto the entryqueryKeynames, creating it when there is none, TanStack Query'ssetQueryData: the entry becomes Success with fresh data and no error, and the queries reading it are told, re-rendering for what changed. The data is shared structurally with what the entry held, as a request landing is. A request in flight is left running and lands over it. A new entry nothing reads expires after DefaultGcTime. A nulldatawrites nothing.