Read-only plugin for stash-it.
Let's say you need to have an instance of stash-it that is only capable of reading from the storage, but not writing, changing or deleting anything.
This plugin will allow you to do just that. And if anyone will try to write / delete something, an error will be thrown.
npm i stash-it-plugin-readonly --save
import { createCache } from 'stash-it';
import createReadOnlyPlugin from 'stash-it-plugin-readonly';
// You can use any adapter
import createMemoryAdapter from 'stash-it-adapter-memory';
const cacheInstance = createCache(createMemoryAdapter());
const readOnlyPlugin = createReadOnlyPlugin();
const readOnlyCacheInstance = cacheInstance.registerPlugins([ readOnlyPlugin ]);
// This will work
readOnlyCacheInstance.hasItem('key');
// But this will throw
readOnlyCacheInstance.removeItem('key');
// or this
readOnlyCacheInstance.setItem('key', 'value');
Methods that will throw are: setItem, addExtra, setExtra and removeItem. All other will work just fine.