Re: [ServiceWorker] Can caches store and retrieve results that are still being written to the cache? (#573)

@jakearchibald, I was thinking more about this:

> do you think this is a sensible thing to live in Fetch? An option to only get the response if it's 
currently in-flight.
```
fetch('/').then(function(response) {
   // ...
});
fetch('/', {
  onlyInFlightStuffPlease: true
}).then(function(response) {
   // ...
});
```

It seems the browser would have to cache the in-flight responses somewhere.  With multi-process architectures, this may not be super straightforward.

I still think this would be better to add to Cache.  Instead of implicitly creating a cache we would explicitly expose the capability on the API available to content.  Then libraries could implement a "in-flight only fetch" feature using this primitive.

For example, lets say we added `{ fetchIfMissing: true }` and `{ bodyComplete: true }` to QueryParams, then a library could do something like this:

```
function fetchInFlightOnly(request) {
  var cache;
  return caches.open('FetchInFlightOnly').then(function(c) {
    cache = c;
    return cache.match(request, { fetchIfMissing: true });
  }).then(function(response) {
    cache.delete(request, { bodyComplete: true });
    return response;
  });
}
```

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/573#issuecomment-66672253

Received on Thursday, 11 December 2014 19:20:46 UTC