From b0490158fb3e452f56c4a0d29760b7c6d7084dc0 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Tue, 6 Sep 2016 17:58:20 -0400 Subject: [PATCH] feat(bypassCache): allow links to bypass LRU cache --- index.js | 5 ++++- test/purge.test.js | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a027650..d7ca2eb 100644 --- a/index.js +++ b/index.js @@ -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]; @@ -30,7 +34,6 @@ function createLink(address, options, type, method) { return link; }); - links[linkHash] = linkPromise; return linkPromise; } diff --git a/test/purge.test.js b/test/purge.test.js index 66951ed..855b368 100644 --- a/test/purge.test.js +++ b/test/purge.test.js @@ -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(); }); @@ -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; + }); + }); + });