in-mem-cache
Simple in memory cache that supports TTL and entry reaping
Last updated 3 years ago by austinkelleher .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install in-mem-cache 
SYNC missed versions from official npm registry.

in-mem-cache

JavaScript in memory cache that supports reaping

Installation

npm install in-mem-cache --save

Usage

const InMemoryCache = require('in-mem-cache');

const cache = InMemoryCache.create();
const myKey = 'hello';

cache.put(myKey, 'world');
let value = cache.get(myKey); // 'world'

The cache will emit an event when cache entries are put and deleted if the emitEntryChanges option is set;

const cache = InMemoryCache.create({ emitEntryChanges: true });

cache.on(`put:${myKey}`, (data) => {
  // data === the entryData that was initially inserted
});

cache.on(`delete:${myKey}`, (data) => {
  // data === the entryData that was initially inserted
});

cache.put(myKey, myData); // triggers the put listener
cache.delete(myKey); // triggers the delete listener

Alternatively, the option can also be set as an option when values are being set.

const cache = InMemoryCache.create();

cache.on(`put:${myKey}`, (data) => {
  // data === the entryData that was initially inserted
});

cache.on(`delete:${myKey}`, (data) => {
  // data === the entryData that was initially inserted
});

cache.put(myKey, myData, { emitEntryChanges: true }); // triggers the put listener
cache.delete(myKey); // triggers the delete listener

Note: Setting the option on the entry will override the default cache option. This allows for finer control over what entries the cache will (or will not) emit events for.

Current Tags

  • 1.0.3                                ...           latest (3 years ago)

4 Versions

  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (1)
Dev Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |