0.3.0 • Published 5 years ago

cachemyr v0.3.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

CircleCI

cachemyr

Cachemyr/kaʃˈmɪə is simple in-memory cache storage module for node.

This is alpha state module. Some of APIs can be changed by update.

How to:

Install

// for 'npm' user
$ npm i cachemyr

// for 'yarn' user
$ yarn add cachemyr

Use

// TODO:

This is example for user:

const mc = require('cachemyr')

mc.put('key-1', 1)
console.log(mc.get('key-1')) // 1

mc.delete('key-1')
console.log(mc.get('key-1')) // null

mc.put('key-2', 2, 6000, (key, value) => {
    // called when data with key `key-2` has been expired (after 6 second)
})

console.log(mc.getLength()) // 1 (<'key-2', 2>)

API

put: void

Put key-value data to storage

VariableTypeDescription
keystringKey of KV(key-value) data
valueanyValue of KV data
durationnumber(optional)Length of duration(ms) to keep this data
timeoutCBFunction(optional)Callback function to be called when added data has been expired
overflowCBFunction(optional)Callback function when memory usage of storage has overrun the value defined in configuration

get: any | null

Get value of key from storage. Returns null when there is no key.

VariableTypeDescription
keystringKey of KV data
instantRemovalboolean(optioanl)Remove after get when set to true

remove: void

Remove key-value set from storage

VariableTypeDescription
keystringKey of KV data

drop: void

Remove all data in storage

getLength: number

Return number of key-value set in storage

Contribution

Improvements, bug report & fix, document updates, and ideas are all welcome.

Build command:

$ yarn build // build module

$ yarn test // test module
0.3.0

5 years ago

0.3.0-beta.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago