Skip to content
Browse files

(api) ability to disable cache via resourcer.cache

  • Loading branch information...
1 parent 0fd2e47 commit 222d660c54c470a07245317472949dc9a613faa0 @cloudhead committed Apr 13, 2011
Showing with 8 additions and 3 deletions.
  1. +7 −3 lib/resourcer/cache.js
  2. +1 −0 lib/resourcer/core.js
View
10 lib/resourcer/cache.js
@@ -1,7 +1,7 @@
var resourcer = require('resourcer');
-resourcer.cache = {
+resourcer.caches = {
stores: [],
push: function (store) {
return this.stores.push(store);
@@ -16,13 +16,13 @@ this.Cache = function (options) {
this.size = 0;
this.store = {};
- resourcer.cache.push(this);
+ resourcer.caches.push(this);
};
this.Cache.prototype = {
get: function (id) {
var that = this;
-
+ if (! resourcer.cache) { return }
if (! id) { return }
else if (Array.isArray(id)) {
return id.map(function (k) {
@@ -33,17 +33,20 @@ this.Cache.prototype = {
}
},
put: function (id, obj) {
+ if (! resourcer.cache) { return }
if (! this.has(id)) { this.size ++ }
this.store[id] = obj;
},
update: function (id, obj) {
+ if (! resourcer.cache) { return }
if (id in this.store) {
for (var k in obj) {
this.store[id][k] = obj[k];
}
}
},
clear: function (id) {
+ if (! resourcer.cache) { return }
if (id) {
this.size --;
delete(this.store[id]);
@@ -53,6 +56,7 @@ this.Cache.prototype = {
}
},
has: function (id) {
+ if (! resourcer.cache) { return }
return id in this.store;
}
};
View
1 lib/resourcer/core.js
@@ -15,6 +15,7 @@ resourcer.resources = {};
resourcer.Resource = require('resourcer/resource').Resource;
resourcer.engines = require('resourcer/engines');
resourcer.connection = new(resourcer.engines.memory.Connection);
+resourcer.cache = true;
//

2 comments on commit 222d660

@indexzero

Tests need updating against this:

$ vows test/cache-test.js 
✗✗
node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
TypeError: Cannot call method 'clear' of undefined
    at Object. (/Users/Charlie/GitHub/resourcer/test/cache-test.js:53:33)
    at run (/usr/local/lib/node/.npm/vows/0.5.8/package/lib/vows/suite.js:130:31)
    at EventEmitter. (/usr/local/lib/node/.npm/vows/0.5.8/package/lib/vows/suite.js:203:40)
    at EventEmitter.emit (events.js:81:20)
    at /usr/local/lib/node/.npm/vows/0.5.8/package/lib/vows/context.js:32:52
    at /usr/local/lib/node/.npm/vows/0.5.8/package/lib/vows/context.js:46:29
    at /Users/Charlie/GitHub/resourcer/lib/resourcer/resource.js:446:17
    at /Users/Charlie/GitHub/resourcer/lib/resourcer/resource.js:147:21
    at loop (/Users/Charlie/GitHub/resourcer/lib/resourcer/resource.js:63:17)
    at Function.runAfterHooks (/Users/Charlie/GitHub/resourcer/lib/resourcer/resource.js:65:10)

Offending line (cache-test.js : line 54):

resourcer.cache.clear();

Patch coming.

@indexzero

Fix: indexzero/resourcer@073857f

Tests still seem to be failing in cache-test.js. Overall I'm seeing this now when running the suite:
✗ Errored » 151 honored ∙ 4 broken ∙ 2 errored (0.389s)

What are you seeing? I still have some divergent code around validation but our forks are pretty close to in-sync now.

Please sign in to comment.
Something went wrong with that request. Please try again.