(key: string, staleTime: number)
| 112 | * Exported for testing purposes. |
| 113 | */ |
| 114 | export function isEntryStale(key: string, staleTime: number): boolean { |
| 115 | const entry = getCacheEntry(key) |
| 116 | if (!entry) return true |
| 117 | |
| 118 | // If we have successful data, use its timestamp for staleness |
| 119 | if (entry.dataUpdatedAt !== 0) { |
| 120 | return staleTime === 0 || Date.now() - entry.dataUpdatedAt > staleTime |
| 121 | } |
| 122 | |
| 123 | // No successful data - check if we have a recent error |
| 124 | // Use errorUpdatedAt to prevent rapid retries on persistent errors |
| 125 | if (entry.errorUpdatedAt !== null) { |
| 126 | return staleTime === 0 || Date.now() - entry.errorUpdatedAt > staleTime |
| 127 | } |
| 128 | |
| 129 | // No data and no error timestamp - entry is stale |
| 130 | return true |
| 131 | } |
| 132 | |
| 133 | function setQueryFetching(key: string, fetching: boolean): void { |
| 134 | const wasFetching = cache.fetchingKeys.has(key) |
no test coverage detected