IMC is an In-Memory Cache key-value store.
import cache from 'imc';
cache.set('key', 'value');
cache.get('key'); // 'value'NPM:
$ npm install imc --saveYarn:
$ yarn add imcCDN:
<script src="https://unpkg.com/imc@latest/umd/imc.min.js"></script>
<script>
var cache = window.IMC.cache;
var Cache = window.IMC.Cache;
</script>// CommonJS
const { Cache, cache } = require('imc');
// ES Modules
import cache, { Cache } from 'imc';You can either use the global cache store:
// cache is also a default export
import { cache } from 'imc';Or create a local cache store:
import { Cache } from 'imc';
const cache = new Cache();When instantiating a new cache store, the initial state can be set:
const cache = new Cache({ key: 'value' });Set key-value:
cache.set('key', 'value');Set key-value using object:
cache.set({ key: 'value' });Set multiple keys and values, which are merged to the store object:
cache.set({
key: 'value',
answer: 42,
});Get value from key:
cache.get('key'); // 'value'If key-value does not exist, it will return undefined:
cache.get('invalid'); // undefinedTo differentiate from a key-value that hasn't be set, you can use null:
cache.set('invalid', null);Delete key-value from store:
cache.delete('key');Clear store:
cache.clear();This means the store becomes an empty object:
cache.get(); // {}Run tests with coverage:
$ npm testRun tests in watch mode:
$ npm run test:watchLint files:
$ npm run lintFix lint errors:
$ npm run lint:fixOnly collaborators with credentials can release and publish:
$ npm run release
$ git push --follow-tags && npm publish