workbox icon indicating copy to clipboard operation
workbox copied to clipboard

Ship CacheNetworkRace as part of workbox-strategies

Open jeffposnick opened this issue 3 years ago • 15 comments

Library Affected: workbox-strategies

We currently have code for a "cache and network race" strategy in our docs. The entirety of it looks like:

import {Strategy} from 'workbox-strategies';

class CacheNetworkRace extends Strategy {
  _handle(request, handler) {
    const fetchAndCachePutDone = handler.fetchAndCachePut(request);
    const cacheMatchDone = handler.cacheMatch(request); 

    return new Promise((resolve, reject) => {
      fetchAndCachePutDone.then(resolve);
      cacheMatchDone.then((response) => response && resolve(response));

      // Reject if both network and cache error or find no response.
      Promise.allSettled([fetchAndCachePutDone, cacheMatchDone]).then((results) => {
        const [fetchAndCachePutResult, cacheMatchResult] = results;
        if (fetchAndCachePutResult.status === 'rejected' && !cacheMatchResult.value) {
          reject(fetchAndCachePutResult.reason);
        }  
      });
    });
  }
}

Some folks have asked if we could ship it as part of workbox-strategies to make it more "official."

jeffposnick avatar Nov 30 '21 14:11 jeffposnick

Off-topic for this PR, but when would it be the case that the disk is slower than network? On slow and old HDDs?

kurtextrem avatar Dec 02 '21 20:12 kurtextrem

There's some analysis at https://simonhearne.com/2020/network-faster-than-cache/

jeffposnick avatar Dec 02 '21 22:12 jeffposnick

Hey, I am interested in this issue. Could you guide me a bit? From where should I start?

Midas847 avatar Jan 21 '22 04:01 Midas847

Hello, I'm new to open source and I would like to give this a try! If I understood the issue description correctly, the above-mentioned 'cache and network race' code snippet needs to be integrated with workbox-strategies. Please correct me if I am wrong and I would like to start working on this asap.

The5cheduler avatar Apr 18 '22 00:04 The5cheduler

Hi there is anyone working on this issue? If not may i please try this one out? @parthpatel9414 or @Midas847 may you please advise me if this has been worked on?

regulas1 avatar Jul 29 '22 05:07 regulas1

Hey team, can someone please confirm if anyone is working on this issue, If not I would love to know more about it and resolve it :)

shreyash184 avatar Jan 28 '23 09:01 shreyash184

Guys happy to assist if anyone is working on this issue

Aditya-Naresh avatar Apr 06 '23 16:04 Aditya-Naresh

@Aditya-Naresh Can you please assign this to me?

ZainGulbaz avatar Apr 11 '23 07:04 ZainGulbaz

@ZainGulbaz I think you have to ask @jeffposnick

Aditya-Naresh avatar Apr 11 '23 15:04 Aditya-Naresh

Jeff left Google 8 months ago. The new maintainer finally confirmed the other day that workbox has been deprecated.

#3149

nickchomey avatar Apr 11 '23 17:04 nickchomey

Workbox is not deprecated. It is understaffed, we are not releasing a new version this year, but it is in our roadmap and we want to find a path via the community or another organization to staff it better.

tropicadri avatar Apr 11 '23 21:04 tropicadri

Hi @tropicadri, I am new here but really wanna contribute to Workbox. Can you guide me a little to work on this?

mrpriyansh avatar Jun 08 '23 01:06 mrpriyansh

Hey, can I work on this issue

dpsi9 avatar Jun 18 '23 19:06 dpsi9

Hello @tropicadri, please let me know how I could contribute! I'm really interested and would appreciate guidance.

gvc222 avatar Sep 19 '23 05:09 gvc222

Is it still open ? I want to do this task

yagiz-aydin avatar Oct 09 '23 14:10 yagiz-aydin