Socket
Book a DemoInstallSign in
Socket

nodex-cache

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodex-cache

A simple node js cache manager

1.0.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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

Keywords

node

FAQs

Package last updated on 12 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.