Skip to content

Commit

Permalink
fix(link-cache): always bypass cache for dynamic links
Browse files Browse the repository at this point in the history
Links created with a `null` address are allowed, as long as they
are also created with a dynamic `source`. In this cases we should
absolutely not cache the resultant link, as there is no other way
to differentiate the calls.

A test has also been added for the previously added `bypassCache`
functionality.
  • Loading branch information
mbroadst committed Sep 22, 2016
1 parent 5311c43 commit 9c46497
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ var ttl = 60000;
var purgeTimeout = null;

function createLink(address, options, type, method) {
if (address === null) {
// for the case of dynamically created links, we always want to bypass
// the link cache
return method(address, options);
}

if (options && options.hasOwnProperty('bypassCache') && !!options.bypassCache) {
return method(address, options);
}
Expand Down
26 changes: 26 additions & 0 deletions test/link-cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,30 @@ describe('basic behavior', function() {
});
});
});

it('should allow a user to bypass the link cache explicitly', function() {
return test.client.connect(config.address)
.then(function() {
return Promise.all([
test.client.createReceiver('amq.topic'),
test.client.createReceiver('amq.topic', { bypassCache: true })
]);
})
.spread(function(link1, link2) {
expect(link1).to.not.eql(link2);
});
});

it('should bypass the cache for dynamic links', function() {
return test.client.connect(config.address)
.then(function() {
return Promise.all([
test.client.createReceiver(null, { attach: { source: { dynamic: true } } }),
test.client.createReceiver(null, { attach: { source: { dynamic: true } } })
]);
})
.spread(function(link1, link2) {
expect(link1).to.not.eql(link2);
});
});
});

0 comments on commit 9c46497

Please sign in to comment.