Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/queryCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function makeQueryCache() {
}

cache.clear = () => {
Object.values(cache.queries).forEach(query => query.clear())
cache.queries = {}
notifyGlobalListeners()
}
Expand Down Expand Up @@ -516,6 +517,12 @@ export function makeQueryCache() {
query.scheduleStaleTimeout()
}

query.clear = () => {
clearTimeout(query.staleTimeout)
clearTimeout(query.cacheTimeout)
query.cancel()
}

return query
}

Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ export interface CachedQuery<T> {
setData(
dataOrUpdater: unknown | ((oldData: unknown | undefined) => unknown)
): void
clear(): void
}

export interface QueryCache {
Expand Down Expand Up @@ -701,7 +702,7 @@ export interface QueryCache {
): void
isFetching: number
subscribe(callback: (queryCache: QueryCache) => void): () => void
clear(): Array<CachedQuery<unknown>>
clear(): void
}

export const queryCache: QueryCache
Expand Down