From f3c37617720da85a3db5fc32c6451cdfb0944525 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 5 Jul 2018 09:42:28 +0200 Subject: [PATCH] refactor: opts.useCache Adds option for useCache to github and gitlab wrappers. --- lib/platform/github/gh-got-wrapper.js | 3 ++- lib/platform/gitlab/gl-got-wrapper.js | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/platform/github/gh-got-wrapper.js b/lib/platform/github/gh-got-wrapper.js index b628009ab7..9ac5d79e6a 100644 --- a/lib/platform/github/gh-got-wrapper.js +++ b/lib/platform/github/gh-got-wrapper.js @@ -9,7 +9,8 @@ async function get(path, opts, retries = 5) { /* eslint-disable no-param-reassign */ opts = Object.assign({}, opts); const method = opts.method ? opts.method : 'get'; - if (method === 'get' && cache[path]) { + const useCache = opts.useCache || true; + if (method === 'get' && useCache && cache[path]) { logger.trace({ path }, 'Returning cached result'); return cache[path]; } diff --git a/lib/platform/gitlab/gl-got-wrapper.js b/lib/platform/gitlab/gl-got-wrapper.js index e517af745b..4e3b0a0db6 100644 --- a/lib/platform/gitlab/gl-got-wrapper.js +++ b/lib/platform/gitlab/gl-got-wrapper.js @@ -4,14 +4,17 @@ const parseLinkHeader = require('parse-link-header'); let cache = {}; async function get(path, opts, retries = 5) { - const method = opts && opts.method ? opts.method : 'get'; - if (method === 'get' && cache[path]) { + /* eslint-disable no-param-reassign */ + opts = Object.assign({}, opts); + const method = opts.method ? opts.method : 'get'; + const useCache = opts.useCache || true; + if (method === 'get' && useCache && cache[path]) { logger.debug({ path }, 'Returning cached result'); return cache[path]; } logger.debug({ path }, method.toUpperCase()); const res = await glGot(path, opts); - if (opts && opts.paginate) { + if (opts.paginate) { // Check if result is paginated try { const linkHeader = parseLinkHeader(res.headers.link); -- GitLab