Last updated 5 months ago
npm install stash-it

As stash-it is just a core module without any storage predefined, you need to provide an adapter that will enable you to store your data in a persistence of your choosing. For this example let's use the simplest one: stash-it-adapter-memory.

npm install stash-it-adapter-memory

If you want to use a different adapter, head off to available adapters page.

Now, let's combine and use them:

import { createCache } from 'stash-it';
import createMemoryAdapter from 'stash-it-adapter-memory';
const adapter = createMemoryAdapter();
const cache = createCache(adapter);
cache.setItem('key', 'some very often fetched value I need to store');
cache.hasItem('key'); // true
const item = cache.getItem('key');
console.log(item.value); // some very often fetched value I need to store
cache.removeItem('key'); // true
cache.hasItem('key'); // false