Skip to content

Commit

Permalink
feat(bypassCache): allow links to bypass LRU cache
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Sep 6, 2016
1 parent 6e332cc commit b049015
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ var ttl = 60000;
var purgeTimeout = null;

function createLink(address, options, type, method) {
if (options && options.hasOwnProperty('bypassCache') && !!options.bypassCache) {
return method(address, options);
}

var linkHash = hash({ type: type, address: address, options: options });
if (links.hasOwnProperty(linkHash)) {
var entry = links[linkHash];
Expand All @@ -30,7 +34,6 @@ function createLink(address, options, type, method) {
return link;
});


links[linkHash] = linkPromise;
return linkPromise;
}
Expand Down
16 changes: 15 additions & 1 deletion test/purge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var amqp = require('amqp10'),

var test = {};
describe('purging', function() {
before(function() { amqp.use(linkCache({ ttl: 10 })); });
beforeEach(function() {
if (!!test.client) delete test.client;
amqp.use(linkCache({ ttl: 10 }));
test.client = new AMQPClient();
});

Expand Down Expand Up @@ -41,4 +41,18 @@ describe('purging', function() {
.tap(function(sender) { sender2 = sender; })
.then(function() { expect(sender1).to.not.eql(sender2); });
});

it('should not purge links that indicate they should bypass the cache', function() {
var sender;
return test.client.connect(config.address)
.then(function() { return test.client.createSender('amq.topic', { bypassCache: true }); })
.then(function(s) { sender = s; })
.delay(50)
.then(function() {
var state = sender.linkSM.getMachineState();
expect(state).to.equal('ATTACHED');
sender = null;
});
});

});

0 comments on commit b049015

Please sign in to comment.