Skip to content

Commit

Permalink
Merge pull request #27 from neonstalwart/now
Browse files Browse the repository at this point in the history
put `now` in scope for the usage in `get`
  • Loading branch information
kriszyp committed May 15, 2012
2 parents b9a3040 + 051daba commit 0108492
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions store/cache.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* This is a wrapper store that can add caching to a store
*/
var table = {},
when = require("promised-io/promise").when;
var when = require("promised-io/promise").when;

exports.Cache = function(store, cacheStore, options){
options = options || {};
Expand All @@ -11,9 +10,10 @@ exports.Cache = function(store, cacheStore, options){
var cleanupInterval = options.cleanupInterval || 1000;
var lastAccess = {};
var nextCheck = new Date().getTime();
var now;
cleanup();
function cleanup(){
var now = new Date().getTime();
now = new Date().getTime();
if(now > nextCheck){
nextCheck = now + cleanupInterval;
return when(cacheStore.query("expires<$1", {parameters:[now]}), function(results){
Expand All @@ -29,7 +29,7 @@ exports.Cache = function(store, cacheStore, options){
lastAccess[id] = now++;
if(!cached){
if(store){
cacheStore.put(cached = store.get[id], {id:id});
cacheStore.put(cached = store.get(id), {id:id});
}
}
return cached;
Expand Down Expand Up @@ -71,4 +71,4 @@ exports.Cache = function(store, cacheStore, options){
cacheStore["delete"](id);
}
};
};
};

0 comments on commit 0108492

Please sign in to comment.