nodex-cache
A simple node js cache manager
Last updated 2 years ago by lijukrks .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nodex-cache 
SYNC missed versions from official npm registry.

nodex-cache

A simple caching module for node js that has set, get and delete methods. Keys can have a timeout (ttl) after which they expire and are deleted from the cache.

Installation

npm i --save nodex-cache

Usage

const node_cache = require('nodex-cache');
let { cache, expire } = node_cache;

Simple Cache

const simpleCache = cache();

simpleCache.set('a', 1)
simpleCache.set('b', 3)

console.log(simpleCache.remove('b')) // 3
console.log(simpleCache.get('a')) // 1
console.log(simpleCache.remove('b')) // undefined

Expiring Cache

const expirationHandler = (key, value) => {
    console.log(`expired ${key}: ${value}`) // expired b: 2
}
const expiringCache = expire(cache(), expirationHandler)

expiringCache.set('a', 1, 1000)
expiringCache.set('b', 2) //default expiry is 1000
expiringCache.set('c', 3) //default expiry is 1000

console.log(expiringCache.remove('b')) // 2
console.log(expiringCache.get('a')) // 1

setTimeout(() => {
    console.log(expiringCache.get('a')) // undefined
}, 1200)

License

MIT © Liju Kuriakose

Current Tags

  • 1.0.1                                ...           latest (2 years ago)

2 Versions

  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (8)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |