* Check if we're within the stale-while-revalidate window for a stale response * @param {import('../../types/cache-interceptor.d.ts').default.GetResult} result * @returns {boolean}
(result)
| 96 | * @returns {boolean} |
| 97 | */ |
| 98 | function withinStaleWhileRevalidateWindow (result) { |
| 99 | const staleWhileRevalidate = result.cacheControlDirectives?.['stale-while-revalidate'] |
| 100 | if (!staleWhileRevalidate) { |
| 101 | return false |
| 102 | } |
| 103 | |
| 104 | const now = Date.now() |
| 105 | const staleWhileRevalidateExpiry = result.staleAt + (staleWhileRevalidate * 1000) |
| 106 | return now <= staleWhileRevalidateExpiry |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @param {DispatchFn} dispatch |