Re: [ServiceWorker] Cache transactions & fixing `addAll` (#823)

> So we have responses of wildly varying size being stored under the same request? What kind of html resources have this characteristic? I'm probably wrong, but it seems to me resources are mostly stable in size over the short term.
>
> Also, they could use a vary header to avoid this situation, no?

I'm not following this, but I'm pretty jetlagged right now (hence all the spelling and grammar mistakes - more than usual). Taking your example, but making it about age, not size:

```js
caches.open('foo').then(cache => {
  cache.keys().then(requests => {
    return requests.map(request => {
      cache.match(request).then(response => {
        return isTooOld(response) ? request : null;
      });
    });
  }).then(requestsToDelete => {
    return Promise.all(requestsToDelete.map(request => {
      if (!request) return;
      return cache.delete(request);
    }));
  });
});
```

When we `cache.match(requests[0])`, many writes may have happened by the time we get to `cache.delete(requests[0])`, so I may be deleting a response other than the one that `isTooOld(response)`.

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

Received on Sunday, 24 January 2016 01:28:43 UTC