(moving from https://github.com/slightlyoff/ServiceWorker/issues/906)
localStorage is handy for much use cases, but unfortunately it’s api based on Sync. so in service worker we need to use Indexed DB for every kind of data, only if you need to store 1byte flag.
I think if we don’t need index for large data search, and don’t wanna preparing ceremony for storing data, it’s better to have a localStorage which has Async API.
or other sight of view, Cache API is more handy than IDB, but it’s specialised for Request/Response class. AsyncLocalStorage will looks something like CacheAPI which is generalised for Plain Old JavaScript Object. (we may see it as parent class of Cache API)
this will solve may use case I think, for example…
- every use case for localStorage at window context
- saving request data for sync event
- saving simple/single/small data like flag, counter etc
- no need to prepare scheme before using (at install/activate)
will seems…
// class AsyncStorage
asyncStorage.open('v1').then((store) => {
store.put('key', {data:'value'}).then();
store.match('key').then(console.log.bind(cosnole)); // { data: 'value' }
// etc but, no add/addAll
});
// class Caches extends AsyncStorage
// with adding method like add/addAll
// and optimised for Request/Response