expirable-hash-table
v1.0.1
Published
Expirable HashTable to enable timeout-based item removal from HashTable.
Downloads
177
Readme
expirable-hash-table
Expirable HashTable to enable timeout-based item removal from HashTable.
Install
npm install expirable-hash-table
Use
var ExpirableHashTable = require('expirable-hash-table')
var myTable = new ExpirableHashTable(1000) // default timeout in miliseconds
myTable.set('key', 'value', 3000) // optional timeout in miliseconds
myTable.get('key') // -> value
myTable.remove('key') // -> ExpirableHashTable
myTable.has('key') // -> true/false
myTable.purge() // -> ExpirableHashTable
myTable.toArray() // -> Array
myTable.size() // -> Integer
myTable.on('change', function() {
// A change event is emitted ever time an item is added, updated or removed
})
myTable.once('<key>:expired', function() {
// A expired event is emitted when a given item expires. Useful if a specific item wants to be monitored.
})
License
MIT