Defined in: packages/vue-query/src/queryCache.ts:16
Vue-aware subclass of @tanstack/query-core's QueryCache. find/findAll also accept a MaybeRefDeep filters object, so refs can be passed directly without unwrapping. Access it via queryClient.getQueryCache() — QueryClient constructs one of these by default.
new QueryCache(config): QueryCache;Defined in: packages/query-core/src/queryCache.ts:126
QueryCacheConfig = {}
QueryCache
QC.constructorconfig: QueryCacheConfig = {};Defined in: packages/query-core/src/queryCache.ts:126
QC.configprotected listeners: Set<QueryCacheListener>;Defined in: packages/query-core/src/subscribable.ts:2
QC.listenersbuild<TQueryFnData, TError, TData, TQueryKey>(
client,
options,
state?): Query<TQueryFnData, TError, TData, TQueryKey>;Defined in: packages/query-core/src/queryCache.ts:147
Returns the existing Query instance for the given options' queryKey/queryHash, or builds and adds a new one to the cache if none exists yet. Used by framework adapters and plugins (e.g. broadcast/persistence) that need to get-or-create a Query directly, bypassing the reactive QueryObserver machinery.
TQueryFnData = unknown
TError = Error
TData = TQueryFnData
TQueryKey extends readonly unknown[] = readonly unknown[]
QueryClient
WithRequired<QueryOptions<TQueryFnData, TError, TData, TQueryKey, never>, "queryKey">
QueryState<TData, TError>
Query<TQueryFnData, TError, TData, TQueryKey>
const queryCache = queryClient.getQueryCache()
const query = queryCache.build(queryClient, {
queryKey: ['posts'],
queryFn: fetchPosts,
})QC.buildclear(): void;Defined in: packages/query-core/src/queryCache.ts:232
Removes all queries from the cache.
void
const queryCache = queryClient.getQueryCache()
queryCache.clear()QC.clearfind<TQueryFnData, TError, TData>(filters):
| Query<TQueryFnData, TError, TData, readonly unknown[]>
| undefined;Defined in: packages/vue-query/src/queryCache.ts:17
A slightly more advanced method that can be used to get an existing query instance from the cache. This instance not only contains all the state for the query, but all of the instances, and underlying guts of the query as well. If the query does not exist, undefined is returned.
This is not typically needed for most applications, but can come in handy when needing more information about a query in rare scenarios (e.g. looking at query.state.dataUpdatedAt to decide whether a query is fresh enough to be used as an initial value).
TQueryFnData = unknown
TError = Error
TData = TQueryFnData
MaybeRefDeep<WithRequired<QueryFilters<readonly unknown[]>, "queryKey">>
| Query<TQueryFnData, TError, TData, readonly unknown[]> | undefined
const queryCache = queryClient.getQueryCache()
const query = queryCache.find({ queryKey: ['posts'] })QC.findfindAll(filters): Query<unknown, Error, unknown, readonly unknown[]>[];Defined in: packages/vue-query/src/queryCache.ts:23
An even more advanced method that can be used to get existing query instances from the cache that partially match a query key. If no queries match, an empty array is returned.
This is not typically needed for most applications, but can come in handy when needing more information about queries in rare scenarios.
MaybeRefDeep<QueryFilters<readonly unknown[]>> = {}
Query<unknown, Error, unknown, readonly unknown[]>[]
const queryCache = queryClient.getQueryCache()
const queries = queryCache.findAll({ queryKey: ['posts'] })QC.findAllget<TQueryFnData, TError, TData, TQueryKey>(queryHash):
| Query<TQueryFnData, TError, TData, TQueryKey>
| undefined;Defined in: packages/query-core/src/queryCache.ts:254
Returns the Query instance stored under the given queryHash, or undefined if none exists. Unlike QueryCache#find, this looks up by the already-computed hash rather than by QueryFilters. Used by plugins (e.g. broadcast/hydration) that already have a hash to look up directly.
TQueryFnData = unknown
TError = Error
TData = TQueryFnData
TQueryKey extends readonly unknown[] = readonly unknown[]
string
| Query<TQueryFnData, TError, TData, TQueryKey> | undefined
const queryCache = queryClient.getQueryCache()
const queryHash = hashKey(['posts'])
const query = queryCache.get(queryHash)QC.getgetAll(): Query<unknown, Error, unknown, readonly unknown[]>[];Defined in: packages/query-core/src/queryCache.ts:277
Returns all queries within the cache.
Query<unknown, Error, unknown, readonly unknown[]>[]
const queryCache = queryClient.getQueryCache()
const queries = queryCache.getAll()QC.getAllhasListeners(): boolean;Defined in: packages/query-core/src/subscribable.ts:19
boolean
QC.hasListenersprotected onSubscribe(): void;Defined in: packages/query-core/src/subscribable.ts:23
void
QC.onSubscribeprotected onUnsubscribe(): void;Defined in: packages/query-core/src/subscribable.ts:27
void
QC.onUnsubscriberemove(query): void;Defined in: packages/query-core/src/queryCache.ts:208
Destroys the given Query and removes it from the cache, notifying subscribers with a 'removed' event. A no-op if the query is no longer the one currently stored under its hash (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror removals across QueryCache instances.
Query<any, any, any, any>
void
const queryCache = queryClient.getQueryCache()
const query = queryCache.find({ queryKey: ['posts'] })
if (query) {
queryCache.remove(query)
}QC.removesubscribe(listener): () => void;Defined in: packages/query-core/src/subscribable.ts:8
QueryCacheListener
(): void;void
QC.subscribe