https://github.com/remarkablemark/imc
:key: IMC is an In-Memory Cache key-value store.
https://github.com/remarkablemark/imc
imc in-memory-caching key-value-store
Last synced: 4 months ago
JSON representation
:key: IMC is an In-Memory Cache key-value store.
- Host: GitHub
- URL: https://github.com/remarkablemark/imc
- Owner: remarkablemark
- License: mit
- Created: 2020-05-23T18:53:20.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-03-06T23:59:09.000Z (over 1 year ago)
- Last Synced: 2025-08-09T08:34:18.628Z (10 months ago)
- Topics: imc, in-memory-caching, key-value-store
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/imc
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# IMC
[](https://nodei.co/npm/imc/)
[](https://www.npmjs.com/package/imc)
[](https://travis-ci.org/remarkablemark/imc)
[](https://coveralls.io/github/remarkablemark/imc?branch=master)
**IMC** is an **I**n-**M**emory **C**ache key-value store.
```js
import cache from 'imc';
cache.set('key', 'value');
cache.get('key'); // 'value'
```
[Repl.it](https://repl.it/@remarkablemark/imc) | [JSFiddle](https://jsfiddle.net/remarkablemark/z4s5qcf6/)
## Installation
[NPM](https://www.npmjs.com/package/imc):
```sh
$ npm install imc --save
```
[Yarn](https://yarnpkg.com/package/imc):
```sh
$ yarn add imc
```
[CDN](https://unpkg.com/imc/):
```html
var cache = window.IMC.cache;
var Cache = window.IMC.Cache;
```
## Usage
### Import Module
```js
// CommonJS
const { Cache, cache } = require('imc');
// ES Modules
import cache, { Cache } from 'imc';
```
### Global Cache
You can either use the global cache store:
```js
// cache is also a default export
import { cache } from 'imc';
```
### Local Cache
Or create a local cache store:
```js
import { Cache } from 'imc';
const cache = new Cache();
```
When instantiating a new cache store, the initial state can be set:
```js
const cache = new Cache({ key: 'value' });
```
### Set
Set key-value:
```js
cache.set('key', 'value');
```
Set key-value using object:
```js
cache.set({ key: 'value' });
```
Set multiple keys and values, which are merged to the store object:
```js
cache.set({
key: 'value',
answer: 42,
});
```
### Get
Get value from key:
```js
cache.get('key'); // 'value'
```
If key-value does not exist, it will return `undefined`:
```js
cache.get('invalid'); // undefined
```
To differentiate from a key-value that hasn't be set, you can use `null`:
```js
cache.set('invalid', null);
```
### Delete
Delete key-value from store:
```js
cache.delete('key');
```
### Clear
Clear store:
```js
cache.clear();
```
This means the store becomes an empty object:
```js
cache.get(); // {}
```
## Testing
Run tests with coverage:
```sh
$ npm test
```
Run tests in watch mode:
```sh
$ npm run test:watch
```
Lint files:
```sh
$ npm run lint
```
Fix lint errors:
```sh
$ npm run lint:fix
```
## Release
Only collaborators with credentials can release and publish:
```sh
$ npm run release
$ git push --follow-tags && npm publish
```
## License
[MIT](https://github.com/remarkablemark/imc/blob/master/LICENSE)