Re: [slightlyoff/ServiceWorker] Provide cache.putAll() method (#867)

My intent is to make it easier to write atomic transactions. You could do this:

1. open a cache
2. call `cache.addAll()` which makes a bunch of requests and waits for them to complete

but then my thinking was if the requests fail or the browser session is terminated, you are left with an empty cache. If your versioning system works by `caches.has()`, it might think it's now up-to-date but the cache is empty. Ideally we want to avoid this.

So I tried doing this:

1. make a bunch of requests and wait for them all to complete
2. open a cache
3. write all responses

This means if step 1 fails or is cancelled, there is no empty cache left behind. Right now step 3 has to be a lot of `cache.put()` in parallel, which isn't atomic either, which is the intent behind suggesting `cache.putAll()`. Even then, there is a chance between steps 2 and 3 that something goes wrong and leaves behind an empty cache. At least network latency is not a part of this gap, just write speed.

I am wondering if it would help to have a single atomic "open cache and write this data" operation, but then I guess we're on to transactions?

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/867#issuecomment-206465777

Received on Wednesday, 6 April 2016 17:03:02 UTC