Skip to content

Commit

Permalink
no longer need to JSON.parse/stringify as supermarket does it itself
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrumins committed Sep 15, 2010
1 parent 0fafbac commit 1256b33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions lib/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ function Cart(options) {
options.maxAge = options.maxAge || 3600000; // Expunge after an hour
var dbFile = options.dbFile || __dirname + "/sessions.db";
ConnectStore.call(this, options);
Store(dbFile, function (err, db) {
Store({ filename : dbFile, json : true }, function (err, db) {
if (err) throw err;
self.db = db;
db.filter(
function (key, item) {
item = JSON.parse(item);
return item.lastAccess > Date.now() - options.maxAge;
},
function (key, item) {
Expand All @@ -33,7 +32,7 @@ Cart.prototype.get = function (hash, fn) {
this.db.get(hash, function (err, val) {
if (err) throw err;
if (val) {
fn(null, JSON.parse(val));
fn(null, val);
}
else {
fn();
Expand All @@ -42,7 +41,7 @@ Cart.prototype.get = function (hash, fn) {
};

Cart.prototype.set = function (hash, sess, fn) {
this.db.set(hash, JSON.stringify(sess), function (err) {
this.db.set(hash, sess, function (err) {
if (err) throw err;
if (fn) fn();
});
Expand All @@ -56,10 +55,8 @@ Cart.prototype.destroy = function (hash, fn) {
};

Cart.prototype.length = function (fn) {
process.nextTick(function () {
this.db.length(function (err, len) {
fn(null, len);
});
this.db.length(function (err, len) {
fn(null, len);
});
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "cart",
"version" : "1.0.0",
"version" : "1.0.1",
"description" : "Connect session store using supermarket",
"modules" : {
"index" : "./lib/cart.js"
Expand All @@ -26,7 +26,7 @@
"node": ">=0.2.0"
},
"dependencies" : {
"supermarket" : ">=1.0.5"
"supermarket" : ">=1.0.6"
}
}

0 comments on commit 1256b33

Please sign in to comment.