Skip to content

Commit

Permalink
Pass the cache root's version to LRU collect after the get and set op…
Browse files Browse the repository at this point in the history
…erations have finished mutating the cache. Fixes #507.
  • Loading branch information
trxcllnt authored and sdesai committed Oct 28, 2015
1 parent e318ed7 commit d48c082
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/response/IdempotentResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var getSize = require("./../support/getSize");
var collectLru = require("./../lru/collect");

var arrayClone = require("./../support/array-clone");
var __version = require("./../internal/version");

var isArray = Array.isArray;
var isPathValue = require("./../support/isPathValue");
Expand Down Expand Up @@ -92,7 +93,8 @@ IdempotentResponse.prototype.ensureCollect = function ensureCollect(model) {
var modelCache = modelRoot.cache;

modelRoot.collectionScheduler.schedule(function collectThisPass() {
collectLru(modelRoot, modelRoot.expired, getSize(modelCache), model._maxSize, model._collectRatio);
collectLru(modelRoot, modelRoot.expired, getSize(modelCache),
model._maxSize, model._collectRatio, modelCache[__version]);
});
});

Expand Down
5 changes: 4 additions & 1 deletion lib/response/get/getRequestCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var fastCat = require("./../../get/util/support").fastCat;
var collectLru = require("./../../lru/collect");
var getSize = require("./../../support/getSize");
var AssignableDisposable = require("./AssignableDisposable");
var __version = require("./../../internal/version");

/**
* The get request cycle for checking the cache and reporting
Expand Down Expand Up @@ -75,8 +76,10 @@ module.exports = function getRequestCycle(getResponse, model, results, observer,

var modelRoot = model._root;
var modelCache = modelRoot.cache;
var currentVersion = modelCache[__version];

collectLru(modelRoot, modelRoot.expired, getSize(modelCache),
model._maxSize, model._collectRatio);
model._maxSize, model._collectRatio, currentVersion);
}

});
Expand Down
38 changes: 38 additions & 0 deletions test/falcor/get/get.dataSource-and-cache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,44 @@ describe('DataSource and Partial Cache', function() {
}).
subscribe(noOp, done, done);
});

it('should get a complex argument into a single arg and collect to max cache size.', function(done) {
var model = new Model({
cache: M(),
source: new LocalDataSource(Cache()),
maxSize: 0
});
var cache = model._root.cache;
var onNext = sinon.spy();
model.
get(['lolomo', 0, {to: 1}, 'item', 'title']).
doAction(onNext, noOp, function() {
expect(onNext.calledOnce).to.be.ok;
expect(strip(onNext.getCall(0).args[0])).to.deep.equals({
json: {
lolomo: {
0: {
0: {
item: {
title: 'Video 0'
}
},
1: {
item: {
title: 'Video 1'
}
}
}
}
}
});
}).
finally(function() {
expect(cache['$size']).to.equal(0);
done();
}).
subscribe(noOp, done, noOp);
});
});
describe('_toJSONG', function() {
it('should get multiple arguments into a single _toJSONG response.', function(done) {
Expand Down

0 comments on commit d48c082

Please sign in to comment.