Skip to content

Commit d4ac1e1

Browse files
committed
Add CacheCollectionQueryExtraOptions
1 parent 7513d3b commit d4ac1e1

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

packages/toolkit/src/query/core/buildMiddleware/cacheCollection.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ function isObjectEmpty(obj: Record<any, any>) {
2121
return true
2222
}
2323

24+
export type CacheCollectionQueryExtraOptions = {
25+
/**
26+
* Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_
27+
*
28+
* This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache.
29+
*/
30+
keepUnusedDataFor?: number
31+
}
32+
2433
// Per https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value , browsers store
2534
// `setTimeout()` timer values in a 32-bit int. If we pass a value in that's larger than that,
2635
// it wraps and ends up executing immediately.

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
QueryReturnValue,
1111
} from './baseQueryTypes'
1212
import type { QuerySubState, RootState } from './core'
13+
import type { CacheCollectionQueryExtraOptions } from './core/buildMiddleware/cacheCollection'
1314
import type {
1415
CacheLifecycleMutationExtraOptions,
1516
CacheLifecycleQueryExtraOptions,
@@ -282,16 +283,10 @@ export interface QueryExtraOptions<
282283
QueryArg,
283284
BaseQuery,
284285
ReducerPath
285-
> {
286+
>,
287+
CacheCollectionQueryExtraOptions {
286288
type: DefinitionType.query
287289

288-
/**
289-
* Overrides the api-wide definition of `keepUnusedDataFor` for this endpoint only. _(This value is in seconds.)_
290-
*
291-
* This is how long RTK Query will keep your data cached for **after** the last component unsubscribes. For example, if you query an endpoint, then unmount the component, then mount another component that makes the same request within the given time frame, the most recent value will be served from the cache.
292-
*/
293-
keepUnusedDataFor?: number
294-
295290
/**
296291
* Used by `query` endpoints. Determines which 'tag' is attached to the cached data returned by the query.
297292
* Expects an array of tag type strings, an array of objects of tag types with ids, or a function that returns such an array.

0 commit comments

Comments
 (0)