Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear cache timeouts #495

Merged
merged 2 commits into from
May 17, 2020
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.
Jump to
Jump to file
Failed to load files.
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