0.0.4 • Published 9 years ago

expire-memory v0.0.4

Weekly downloads
1
License
ISC
Repository
github
Last release
9 years ago

Memory Expire

Purpose

in memory key value storage with variable expire times

##Example Usage

var ExpireMemory = require('expire-memory');

var expireMemory = new ExpireMemory();

expireMemory.put('key', 'some value', 1000);

console.log(expireMemory.get('key')); //some value

setTimeout(function (){
  console.log(expireMemory.get('key')); //null
},1001);



expireMemory.put('key2', 'some value', 1000);

console.log(expireMemory.expiry('key2')); // current time that key was set (epoc ms) + 1000

console.log(expireMemory.get('key2')); //some value
expireMemory.put('key2', 'new value', 1010); //previous timeout gets removed and new one is set

setTimeout(function (){
  console.log(expireMemory.get('key2')); //new value
},1001);

expireMemory.put('key1noexpire', 'some value');
expireMemory.put('key2noexpire', 'some value');
expireMemory.put('key3noexpire', 'some value');

console.log(expireMemory.keys()); //[ 'key', 'key2', 'key1noexpire', 'key2noexpire', 'key3noexpire' ]
console.log(expireMemory.hasTimeout('key2')); //true
console.log(expireMemory.hasTimeout('key1noexpire')); //false
console.log(expireMemory.timeouts()); //[ 'key', 'key2' ]
console.log(expireMemory.exists('key1noexpire')); //true
console.log(expireMemory.exists('newkey')); //false
0.0.4

9 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago