Set a time-to-live (TTL) for key-value pairs in medea.
var medea = require('medea');
var ttl = require('medea_ttl');
var db = ttl(medea());
db.open('./.data', function(err) {
db.put('hello', 'world', 2000, function(err) {
if (err) {
console.error(err);
}
setInterval(function() {
db.get('hello', function(err, val) {
console.log('value:', val);
});
}, 500);
});
});
Wrap an existing medea instance.
var medea = require('medea');
var ttl = require('medea_ttl');
var db = ttl(medea());
The options
object is optional. Supported options:
frequency
- This module uses a cleanup interval executing at a frequency specified by this option. The cleanup interval will clear out expired values from the data store. The default is 5 minutes.
prefix
- This option represents how TTL entries are prefixed in the database. The default is ttl-
.
The signature for put
is augmented to add a ttl
parameter. The ttl
parameter should be expressed in milliseconds. It is optional.
- If values are expired between cleanup intervals, calls to
get
will remove the expired value and return null. - Batches do not currently support a TTL parameter, though they may in the future.
MIT