You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
779 B

12 years ago
var Lru = require("lru-cache");
12 years ago
var memory_store = function (args) {
args = args || {};
var self = {};
12 years ago
self.name = 'memory';
var ttl = args.ttl;
var lru_opts = {
max: args.max || 500,
maxAge: ttl ? ttl * 1000 : null
};
var lru_cache = new Lru(lru_opts);
12 years ago
self.set = function (key, value, cb) {
lru_cache.set(key, value);
if (cb) {
cb(null);
}
};
12 years ago
self.get = function (key, cb) {
cb(null, lru_cache.get(key));
};
12 years ago
self.del = function (key, cb) {
lru_cache.del(key);
if (cb) {
cb(null);
}
};
return self;
};
var methods = {
12 years ago
create: function (args) {
return memory_store(args);
}
};
module.exports = methods;