Refactor: remove duplication

I started a little refactoring, moving duplicate code that was common in all three caching layers (IndexedDB, localStorage, InMemoryStorage) into a separate file.