stash-it-adapter-memory
v3.0.1
Published
Memory adapter for stash-it.
Downloads
6
Readme
stash-it-adapter-memory
Memory adapter for stash-it.
It's build in ES6 so if you need to run it in an older environment, you will need to transpile it.
Installation
npm i stash-it-adapter-memory --save
Usage
import { createCache } from 'stash-it';
import createMemoryAdapter from 'stash-it-adapter-memory';
const adapter = createMemoryAdapter();
const cache = createCache(adapter);
And that's it. You are ready to go.
For available methods, check adapters API section (all adapters have the same API).
Heads-up!
Any instance of cache will have access to all items stored in memory, regardles of which cache instance was used. This is because all of the adapters are to behave in the same manner, e.g. connecting to the very same instance of redis / mongo / ... will grant access to the very same items stored there. So should this adapter.
Have a look:
// file1.js - executed BEFORE
import { createCache } from 'stash-it';
import createMemoryAdapter from 'stash-it-adapter-memory';
const adapter = createMemoryAdapter();
const cache1 = createCache(adapter);
cache1.setItem('key', 'value');
// file2.js - executed AFTER
import { createCache } from 'stash-it';
import createMemoryAdapter from 'stash-it-adapter-memory';
const adapter = createMemoryAdapter();
const cache2 = createCache(adapter);
cache2.hasItem('key'); // true
And that goes for all of the methods.
How to bypass this (if needed)?
The suggested way is to use a prefix / suffix plugin.