Building a modern, fast, offline-compatible web app invariably means dealing with caching.
Caching can happen at various layers - database, server, edge, client - however I would argue that the client is the ideal place to cache, and in practice, the hardest. We have two native options in practice - localStorage and IndexedDB - and a plethora of non-native libraries[1] written on top of them to make them more intuitive.
The problem is that the two native options are fundamentally poor, and prone to odd, buggy behavior[2]. LocalStorage is too simple and too slow, and IndexedDB is too complex and too buggy. I want something in between.
The above code is what I would build if I had a magic wand and could create a native client-side caching interface. It would combine the simplicity of localStorage with the capacity and performance of IndexedDB. It would be a simple but opinionated key-value store that requires no schema, versioning, or migrations.
[1] See for example https://pouchdb.com, https://github.com/dexie/Dexie.js, https://github.com/jakearchibald/idb and https://github.com/pamelafox/lscache.
[2] See https://gist.github.com/pesterhazy/4de96193af89a6dd5ce682ce2adff49a for one list of issues.