Skip to content

Commit

Permalink
added delimiter to bucket for options
Browse files Browse the repository at this point in the history
  • Loading branch information
taoyuan committed Jul 30, 2015
1 parent 08f242c commit a219d6e
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 309 deletions.
90 changes: 45 additions & 45 deletions lib/adapters/memory.js
@@ -1,76 +1,76 @@
var LRU = require("lru-cache");

exports.initialize = function initializeMemory(store, callback) {
store.adapter = {
createBucket: function (options) {
return new Memory(options);
}
};
process.nextTick(callback);
store.adapter = {
createBucket: function (options) {
return new Memory(options);
}
};
process.nextTick(callback);
};

function Memory(options) {
options = options || {};
this.name = 'memory';
this.bucket = LRU({
max: options.max || 500,
maxAge: options.ttl ? options.ttl * 1000 : null
});
options = options || {};
this.name = 'memory';
this.bucket = LRU({
max: options.max || 500,
maxAge: options.ttl ? options.ttl * 1000 : null
});
}

Memory.prototype.has = function (key, cb) {
cb(null, this.bucket.has(key));
return this;
cb(null, this.bucket.has(key));
return this;
};

Memory.prototype.get = function (key, cb) {
cb(null, this.bucket.get(key));
return this;
cb(null, this.bucket.get(key));
return this;
};

Memory.prototype.set = function (key, value, cb) {
this.bucket.set(key, value);
if (cb) cb(null, value);
return this;
this.bucket.set(key, value);
if (cb) cb(null, value);
return this;
};

Memory.prototype.getset = function (key, value, cb) {
if (typeof value === 'function') {
cb = value;
value = null;
}
var result = this.bucket.get(key);
this.bucket.set(key, value);
cb(null, result);
return this;
if (typeof value === 'function') {
cb = value;
value = null;
}
var result = this.bucket.get(key);
this.bucket.set(key, value);
cb(null, result);
return this;
};

Memory.prototype.getdel = function (key, cb) {
var result = this.bucket.get(key);
this.bucket.del(key);
cb(null, result);
return this;
var result = this.bucket.get(key);
this.bucket.del(key);
cb(null, result);
return this;
};

Memory.prototype.del = function (key, cb) {
this.bucket.del(key);
if (cb) cb();
return this;
this.bucket.del(key);
if (cb) cb();
return this;
};

Memory.prototype.keys = function (pattern, cb) {
if (typeof pattern === 'function') {
cb = pattern;
}
cb(null, this.bucket.keys());
return this;
if (typeof pattern === 'function') {
cb = pattern;
}
cb(null, this.bucket.keys());
return this;
};

Memory.prototype.clear = function (pattern, cb) {
if (typeof pattern === 'function') {
cb = pattern;
}
var del_count = this.bucket.itemCount;
this.bucket.reset();
cb(null, del_count);
if (typeof pattern === 'function') {
cb = pattern;
}
var del_count = this.bucket.itemCount;
this.bucket.reset();
cb(null, del_count);
};

0 comments on commit a219d6e

Please sign in to comment.