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

Just got into this case where I may need transaction:

I have 2 hash maps: 1) stored on device from previous SW; 2) is in memory which came with new SW.

On `install`:
1) I compute their difference;
2) download **new files** and then put them into _tmp-cache_.

On `activate`:
1) again difference is computed;
2) **old files** deleted from _original-cache_;
3) **moved files** (e.g. renames) are moved inside _original-cache_, original copied are removed (copied with previous URL);
4) **new files** (from `install` event) are merged from _tmp-cache_ to _original-cache_;
5)_tmp-cache_ deleted.

Obvious problem here is that I shouldn't do operations direction on _original-cache_ because everything could be stopped at middle of operation (e.g. computer hard power off).
But thing is--I really want do that, because files are not added/changed so often and merging **new files** into _original-cache_ is much less expensive than moving files from _original-cache_ to _tmp-cache_, and then using _tmp-cache_ as new _original-cache_.

I can be wrong in everything, so please correct me.

---
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/823#issuecomment-210831161

Received on Saturday, 16 April 2016 14:44:30 UTC