packages/core/lib/oneBehindFetch.js
async function oneBehindFetch(input, init) {
  let cachedResponse = cache.get(input);
  if (!cachedResponse) {
    cachedResponse = {
      maxAge: Promise.resolve(MaxAge.zero()),
    };
    cache.set(input, cachedResponse);
  }
  const maxAge = await cachedResponse.maxAge;
  if (!maxAge.isExpired()) {
    // we have to clone the response to enable multiple reads
    const response = await cachedResponse.responsePromise;
    return response.clone();
  }
  const staleResponsePromise = cachedResponse.responsePromise;
  const newResponsePromise = fetch(input, init);
  cachedResponse = {
    responsePromise: newResponsePromise,
    maxAge: newResponsePromise.then(
        (response) => MaxAge.parse(response.headers.get('cache-control'))
    ),
  };
  cache.set(input, cachedResponse);
  const result = staleResponsePromise || newResponsePromise;
  // we have to clone the response to enable multiple reads
  const response = await result;
  return response.clone();
}
async function oneBehindFetch(input, init) {
  let cachedResponse = cache.get(input);
  if (!cachedResponse) {
    cachedResponse = {
      maxAge: Promise.resolve(MaxAge.zero()),
    };
    cache.set(input, cachedResponse);
  }
  const maxAge = await cachedResponse.maxAge;
  if (!maxAge.isExpired()) {
    // we have to clone the response to enable multiple reads
    const response = await cachedResponse.responsePromise;
    return response.clone();
  }
  const staleResponsePromise = cachedResponse.responsePromise;
  const newResponsePromise = fetch(input, init);
  cachedResponse = {
    responsePromise: newResponsePromise,
    maxAge: newResponsePromise.then(
        (response) => MaxAge.parse(response.headers.get('cache-control'))
    ),
  };
  cache.set(input, cachedResponse);
  const result = staleResponsePromise || newResponsePromise;
  // we have to clone the response to enable multiple reads
  const response = await result;
  return response.clone();
}
async function oneBehindFetch ( input , init ) { let cachedResponse = cache . get ( input ) ; if ( ! cachedResponse ) { cachedResponse = { maxAge : Promise . resolve ( MaxAge . zero ( ) ) , } ; cache . set ( input , cachedResponse ) ; } const maxAge = await cachedResponse . maxAge ; if ( ! maxAge . isExpired ( ) ) { // we have to clone the response to enable multiple reads const response = await cachedResponse . responsePromise ; return response . clone ( ) ; } const staleResponsePromise = cachedResponse . responsePromise ; const newResponsePromise = fetch ( input , init ) ; cachedResponse = { responsePromise : newResponsePromise , maxAge : newResponsePromise . then ( ( response ) => MaxAge . parse ( response . headers . get ( 'cache-control' ) ) ) , } ; cache . set ( input , cachedResponse ) ; const result = staleResponsePromise || newResponsePromise ; // we have to clone the response to enable multiple reads const response = await result ; return response . clone ( ) ; }
Implements fetch with a one-behind-caching strategy.

@param {String|Request} input - path or Request instance
@param {Object} init - fetch options
@return Promise<Response>
Implements fetch with a one - behind - caching strategy .