IMC
IMC is an In-Memory Cache key-value store.
;cache;cache; // 'value'
Installation
NPM:
$ npm install imc --save
Yarn:
$ yarn add imc
CDN:
Usage
Import Module
// CommonJSconst Cache cache = ; // ES Modules;
Global Cache
You can either use the global cache store:
// cache is also a default export;
Local Cache
Or create a local cache store:
;const cache = ;
When instantiating a new cache store, the initial state can be set:
const cache = key: 'value' ;
Set
Set key-value:
cache;
Set key-value using object:
cache;
Set multiple keys and values, which are merged to the store object:
cache;
Get
Get value from key:
cache; // 'value'
If key-value does not exist, it will return undefined
:
cache; // undefined
To differentiate from a key-value that hasn't be set, you can use null
:
cache;
Delete
Delete key-value from store:
cache;
Clear
Clear store:
cacheclear;
This means the store becomes an empty object:
cache; // {}
Testing
Run tests with coverage:
$ npm test
Run tests in watch mode:
$ npm run test:watch
Lint files:
$ npm run lint
Fix lint errors:
$ npm run lint:fix
Release
Only collaborators with credentials can release and publish:
$ npm run release$ git push --follow-tags && npm publish