1.0.3 • Published 10 years ago
dictionaryttl v1.0.3
#dictionaryTTL
A Dictionary offering expiration of key-value pairs based on TTL. Based on Domenic Denicola's dict. https://github.com/domenic/dict. This module allows for expiring key-value pairs based on the TTL for each key. The TTL is evaluated when a get is called or the for-each iterator is accessed.
##Installation
npm install dictionaryttl
##Usage
var dictionary = require("dictionaryttl");
var d = dictionary({
key1: "value", //a string value example
key2: {ik1: "value1", ik2:"value2"} // an object example
});
d.has("key1"); // true
d.get("key1"); // "value"
d.size; // 2
d.set("aNewKey", "aNewValue");
d.set("aNewTTLKey", "aNewValue",500); //Set a new ttl key valid for 500 seconds. This pair will not be returned after 500 seconds by any get or iterator ops.
d.delete("key2"); // true
d.forEach(function (value, key) {
console.log("KeyValuePair: " + key + ": " + value);
});
d.clear();
d.size; // 0