MCPcopy Create free account
hub / github.com/nodejs/node / withinStaleWhileRevalidateWindow

Function withinStaleWhileRevalidateWindow

deps/undici/src/lib/interceptor/cache.js:98–107  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

96 * @returns {boolean}
97 */
98function 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

Callers 1

handleResultFunction · 0.85

Calls 1

nowMethod · 0.80

Tested by

no test coverage detected