Refactor: remove duplication

Moves a common method into a mixin called
'cachinglayer' that gets included into all caching
layers (IndexedDB, localStorage and InMemoryStorage)