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

> People have asked for a way to look at the cache and decide what to delete. We don't support that safely right now.

Can you explain the safety issue with this?  For example, this seems somewhat safe today to me:

```
caches.open('foo').then(cache => {
  // Find all responses that are too big
  cache.keys().then(requests => {
    return requests.map(request => {
      cache.match(request).then(response => {
        return isTooOld(response) ? request : null;
      });
    });

  // Now delete them all
  }).then(requestsToDelete => {
    return Promise.all(requestsToDelete.map(request => {
      if (!request) {
        return;
      }
      return cache.delete(request);
    }));
  });
});
```

I agree this could have issues with many threads reading and writing, but right now we mainly have one thread; the service worker.

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

Received on Sunday, 24 January 2016 01:07:45 UTC