Skip to content

Commit

Permalink
Changes Singleton to avoid cache if save_check option is enabled and …
Browse files Browse the repository at this point in the history
…cached instance is not saved (#78)
  • Loading branch information
dresende committed Mar 15, 2013
1 parent 9e4e71f commit 0916416
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Singleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ exports.get = function (key, opts, createCb, returnCb) {
return createCb(returnCb);
}
if (map.hasOwnProperty(key)) {
if (map[key].t !== null && map[key].t <= Date.now()) {
if (opts && opts.save_check && typeof map[key].o.saved == "function" && !map[key].o.saved()) {
// if not saved, don't return it, fetch original from db
return createCb(returnCb);
} else if (map[key].t !== null && map[key].t <= Date.now()) {
delete map[key];
} else {
} else {
return returnCb(map[key].o);
}
}
Expand Down

0 comments on commit 0916416

Please sign in to comment.