diff --git a/lib/datasource/index.ts b/lib/datasource/index.ts index 1ef183c4e8eec3..92a5d9ac6df134 100644 --- a/lib/datasource/index.ts +++ b/lib/datasource/index.ts @@ -2,7 +2,7 @@ import is from '@sindresorhus/is'; import _ from 'lodash'; import { logger } from '../logger'; import { ExternalHostError } from '../types/errors/external-host-error'; -import * as runCache from '../util/cache/run'; +import * as memCache from '../util/cache/memory'; import { clone } from '../util/clone'; import * as allVersioning from '../versioning'; import datasources from './api.generated'; @@ -190,13 +190,13 @@ function getRawReleases( config.lookupName + config.registryUrls; // By returning a Promise and reusing it, we should only fetch each package at most once - const cachedResult = runCache.get(cacheKey); + const cachedResult = memCache.get(cacheKey); // istanbul ignore if if (cachedResult) { return cachedResult; } const promisedRes = fetchReleases(config); - runCache.set(cacheKey, promisedRes); + memCache.set(cacheKey, promisedRes); return promisedRes; } diff --git a/lib/datasource/packagist/index.ts b/lib/datasource/packagist/index.ts index e75d2602f7a66f..78b8d175dbe5c4 100644 --- a/lib/datasource/packagist/index.ts +++ b/lib/datasource/packagist/index.ts @@ -3,8 +3,8 @@ import URL from 'url'; import pAll from 'p-all'; import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; +import * as memCache from '../../util/cache/memory'; import * as packageCache from '../../util/cache/package'; -import * as runCache from '../../util/cache/run'; import * as hostRules from '../../util/host-rules'; import { Http, HttpOptions } from '../../util/http'; import { GetReleasesConfig, ReleaseResult } from '../common'; @@ -221,13 +221,13 @@ async function getAllPackages(regUrl: string): Promise { function getAllCachedPackages(regUrl: string): Promise { const cacheKey = `packagist-${regUrl}`; - const cachedResult = runCache.get(cacheKey); + const cachedResult = memCache.get(cacheKey); // istanbul ignore if if (cachedResult) { return cachedResult; } const promisedRes = getAllPackages(regUrl); - runCache.set(cacheKey, promisedRes); + memCache.set(cacheKey, promisedRes); return promisedRes; } diff --git a/lib/manager/bundler/artifacts.ts b/lib/manager/bundler/artifacts.ts index def4469669ace9..661c7f119514b0 100644 --- a/lib/manager/bundler/artifacts.ts +++ b/lib/manager/bundler/artifacts.ts @@ -3,7 +3,7 @@ import { BUNDLER_INVALID_CREDENTIALS } from '../../constants/error-messages'; import { logger } from '../../logger'; import { platform } from '../../platform'; import { HostRule } from '../../types'; -import { get, set } from '../../util/cache/run'; +import * as memCache from '../../util/cache/memory'; import { ExecOptions, exec } from '../../util/exec'; import { deleteLocalFile, @@ -74,7 +74,7 @@ export async function updateArtifacts( } = updateArtifact; const { compatibility = {} } = config; logger.debug(`bundler.updateArtifacts(${packageFileName})`); - const existingError = get('bundlerArtifactsError'); + const existingError = memCache.get('bundlerArtifactsError'); // istanbul ignore if if (existingError) { logger.debug('Aborting Bundler artifacts due to previous failed attempt'); @@ -182,7 +182,7 @@ export async function updateArtifacts( 'Gemfile.lock update failed due to missing credentials - skipping branch' ); // Do not generate these PRs because we don't yet support Bundler authentication - set('bundlerArtifactsError', BUNDLER_INVALID_CREDENTIALS); + memCache.set('bundlerArtifactsError', BUNDLER_INVALID_CREDENTIALS); throw new Error(BUNDLER_INVALID_CREDENTIALS); } const resolveMatchRe = new RegExp('\\s+(.*) was resolved to', 'g'); diff --git a/lib/util/cache/memory/index.spec.ts b/lib/util/cache/memory/index.spec.ts new file mode 100644 index 00000000000000..9272efecddabc8 --- /dev/null +++ b/lib/util/cache/memory/index.spec.ts @@ -0,0 +1,18 @@ +import * as memCache from '.'; + +describe('getRepoCache', () => { + it('returns undefined if not init', () => { + expect(memCache.get('key1')).toBeUndefined(); + }); + it('sets and gets repo cache', () => { + memCache.init(); + memCache.set('key2', 'value'); + expect(memCache.get('key2')).toEqual('value'); + }); + it('resets', () => { + memCache.init(); + memCache.set('key3', 'value'); + memCache.reset(); + expect(memCache.get('key3')).toBeUndefined(); + }); +}); diff --git a/lib/util/cache/run.ts b/lib/util/cache/memory/index.ts similarity index 100% rename from lib/util/cache/run.ts rename to lib/util/cache/memory/index.ts diff --git a/lib/util/cache/package/index.ts b/lib/util/cache/package/index.ts index d77fdcd8be412e..6962b73c6ad2b1 100644 --- a/lib/util/cache/package/index.ts +++ b/lib/util/cache/package/index.ts @@ -1,5 +1,5 @@ import { RenovateConfig } from '../../../config/common'; -import * as runCache from '../run'; +import * as memCache from '../memory'; import { PackageCache } from './common'; import * as fileCache from './file'; import * as redisCache from './redis'; @@ -15,10 +15,10 @@ export function get(namespace: string, key: string): Promise { return undefined; } const globalKey = getGlobalKey(namespace, key); - if (!runCache.get(globalKey)) { - runCache.set(globalKey, cacheProxy.get(namespace, key)); + if (!memCache.get(globalKey)) { + memCache.set(globalKey, cacheProxy.get(namespace, key)); } - return runCache.get(globalKey); + return memCache.get(globalKey); } export function set( @@ -31,7 +31,7 @@ export function set( return undefined; } const globalKey = getGlobalKey(namespace, key); - runCache.set(globalKey, value); + memCache.set(globalKey, value); return cacheProxy.set(namespace, key, value, minutes); } diff --git a/lib/util/cache/run.spec.ts b/lib/util/cache/run.spec.ts deleted file mode 100644 index df1cba40ebb693..00000000000000 --- a/lib/util/cache/run.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import * as runCache from './run'; - -describe('getRepoCache', () => { - it('returns undefined if not init', () => { - expect(runCache.get('key1')).toBeUndefined(); - }); - it('sets and gets repo cache', () => { - runCache.init(); - runCache.set('key2', 'value'); - expect(runCache.get('key2')).toEqual('value'); - }); - it('resets', () => { - runCache.init(); - runCache.set('key3', 'value'); - runCache.reset(); - expect(runCache.get('key3')).toBeUndefined(); - }); -}); diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts index 43da6e0cb8b371..c140432f724c77 100644 --- a/lib/util/http/index.ts +++ b/lib/util/http/index.ts @@ -2,7 +2,7 @@ import crypto from 'crypto'; import URL from 'url'; import got from 'got'; import { ExternalHostError } from '../../types/errors/external-host-error'; -import * as runCache from '../cache/run'; +import * as memCache from '../cache/memory'; import { clone } from '../clone'; import { applyAuthorization } from './auth'; import { applyHostRules } from './host-rules'; @@ -115,7 +115,7 @@ export class Http { .digest('hex'); if (options.method === 'get' && options.useCache !== false) { // return from cache if present - const cachedRes = runCache.get(cacheKey); + const cachedRes = memCache.get(cacheKey); // istanbul ignore if if (cachedRes) { return resolveResponse(cachedRes, options); @@ -124,16 +124,16 @@ export class Http { const startTime = Date.now(); const promisedRes = got(url, options); if (options.method === 'get') { - runCache.set(cacheKey, promisedRes); // always set if it's a get + memCache.set(cacheKey, promisedRes); // always set if it's a get } const res = await resolveResponse(promisedRes, options); - const httpRequests = runCache.get('http-requests') || []; + const httpRequests = memCache.get('http-requests') || []; httpRequests.push({ method: options.method, url, duration: Date.now() - startTime, }); - runCache.set('http-requests', httpRequests); + memCache.set('http-requests', httpRequests); return res; } diff --git a/lib/workers/pr/changelog/release-notes.ts b/lib/workers/pr/changelog/release-notes.ts index 6947671a84132a..6fcb94c6cb3a98 100644 --- a/lib/workers/pr/changelog/release-notes.ts +++ b/lib/workers/pr/changelog/release-notes.ts @@ -4,8 +4,8 @@ import { linkify } from 'linkify-markdown'; import MarkdownIt from 'markdown-it'; import { logger } from '../../../logger'; +import * as memCache from '../../../util/cache/memory'; import * as packageCache from '../../../util/cache/package'; -import * as runCache from '../../../util/cache/run'; import { GithubHttp } from '../../../util/http/github'; import { GitlabHttp } from '../../../util/http/gitlab'; import { ChangeLogNotes, ChangeLogResult } from './common'; @@ -83,13 +83,13 @@ export function getCachedReleaseList( repository: string ): Promise { const cacheKey = `getReleaseList-${apiBaseUrl}-${repository}`; - const cachedResult = runCache.get(cacheKey); + const cachedResult = memCache.get(cacheKey); // istanbul ignore if if (cachedResult) { return cachedResult; } const promisedRes = getReleaseList(apiBaseUrl, repository); - runCache.set(cacheKey, promisedRes); + memCache.set(cacheKey, promisedRes); return promisedRes; } @@ -254,13 +254,13 @@ export async function getReleaseNotesMdFile( apiBaseUrl: string ): Promise<{ changelogFile: string; changelogMd: string }> | null { const cacheKey = `getReleaseNotesMdFile-${repository}-${apiBaseUrl}`; - const cachedResult = runCache.get(cacheKey); + const cachedResult = memCache.get(cacheKey); // istanbul ignore if if (cachedResult !== undefined) { return cachedResult; } const promisedRes = getReleaseNotesMdFileInner(repository, apiBaseUrl); - runCache.set(cacheKey, promisedRes); + memCache.set(cacheKey, promisedRes); return promisedRes; } diff --git a/lib/workers/pr/changelog/source-github.ts b/lib/workers/pr/changelog/source-github.ts index 7965b583aee929..2a36a600ecf690 100644 --- a/lib/workers/pr/changelog/source-github.ts +++ b/lib/workers/pr/changelog/source-github.ts @@ -2,8 +2,8 @@ import URL from 'url'; import { PLATFORM_TYPE_GITHUB } from '../../../constants/platforms'; import { Release } from '../../../datasource'; import { logger } from '../../../logger'; +import * as memCache from '../../../util/cache/memory'; import * as packageCache from '../../../util/cache/package'; -import * as runCache from '../../../util/cache/run'; import * as hostRules from '../../../util/host-rules'; import { GithubHttp } from '../../../util/http/github'; import * as allVersioning from '../../../versioning'; @@ -47,13 +47,13 @@ async function getTags( repository: string ): Promise { const cacheKey = `getTags-${endpoint}-${repository}`; - const cachedResult = runCache.get(cacheKey); + const cachedResult = memCache.get(cacheKey); // istanbul ignore if if (cachedResult !== undefined) { return cachedResult; } const promisedRes = getTagsInner(endpoint, repository); - runCache.set(cacheKey, promisedRes); + memCache.set(cacheKey, promisedRes); return promisedRes; } diff --git a/lib/workers/pr/changelog/source-gitlab.ts b/lib/workers/pr/changelog/source-gitlab.ts index 72540f21542550..e2f23a431c718f 100644 --- a/lib/workers/pr/changelog/source-gitlab.ts +++ b/lib/workers/pr/changelog/source-gitlab.ts @@ -1,8 +1,8 @@ import URL from 'url'; import { Release } from '../../../datasource'; import { logger } from '../../../logger'; +import * as memCache from '../../../util/cache/memory'; import * as packageCache from '../../../util/cache/package'; -import * as runCache from '../../../util/cache/run'; import { GitlabHttp } from '../../../util/http/gitlab'; import { regEx } from '../../../util/regex'; import * as allVersioning from '../../../versioning'; @@ -52,13 +52,13 @@ async function getTags( repository: string ): Promise { const cacheKey = `getTags-${endpoint}-${versionScheme}-${repository}`; - const cachedResult = runCache.get(cacheKey); + const cachedResult = memCache.get(cacheKey); // istanbul ignore if if (cachedResult !== undefined) { return cachedResult; } const promisedRes = getTagsInner(endpoint, versionScheme, repository); - runCache.set(cacheKey, promisedRes); + memCache.set(cacheKey, promisedRes); return promisedRes; } diff --git a/lib/workers/repository/init/index.ts b/lib/workers/repository/init/index.ts index 5b3688c960e300..f0c901d5055789 100644 --- a/lib/workers/repository/init/index.ts +++ b/lib/workers/repository/init/index.ts @@ -1,7 +1,7 @@ import { RenovateConfig } from '../../../config'; import { logger } from '../../../logger'; import { platform } from '../../../platform'; -import * as runCache from '../../../util/cache/run'; +import * as memCache from '../../../util/cache/memory'; import { checkIfConfigured } from '../configured'; import { checkOnboardingBranch } from '../onboarding/branch'; import { initApis } from './apis'; @@ -11,7 +11,7 @@ import { detectSemanticCommits } from './semantic'; import { detectVulnerabilityAlerts } from './vulnerability'; export async function initRepo(input: RenovateConfig): Promise { - runCache.init(); + memCache.init(); let config: RenovateConfig = { ...input, errors: [], diff --git a/lib/workers/repository/stats.spec.ts b/lib/workers/repository/stats.spec.ts index a391efba56c2ae..a62796aa981944 100644 --- a/lib/workers/repository/stats.spec.ts +++ b/lib/workers/repository/stats.spec.ts @@ -1,14 +1,14 @@ -import * as runCache_ from '../../util/cache/run'; +import * as memCache_ from '../../util/cache/memory'; import { printRequestStats } from './stats'; -jest.mock('../../util/cache/run'); +jest.mock('../../util/cache/memory'); -const runCache: any = runCache_ as any; +const memCache: any = memCache_ as any; describe('workers/repository/stats', () => { describe('printRequestStats()', () => { it('runs', () => { - runCache.get = jest.fn(() => [ + memCache.get = jest.fn(() => [ { method: 'get', url: 'https://api.github.com/api/v3/user', diff --git a/lib/workers/repository/stats.ts b/lib/workers/repository/stats.ts index 167a8b659df7b3..2cf727b4314042 100644 --- a/lib/workers/repository/stats.ts +++ b/lib/workers/repository/stats.ts @@ -1,9 +1,9 @@ import URL from 'url'; import { logger } from '../../logger'; -import * as runCache from '../../util/cache/run'; +import * as memCache from '../../util/cache/memory'; export function printRequestStats(): void { - const httpRequests = runCache.get('http-requests'); + const httpRequests = memCache.get('http-requests'); if (!httpRequests) { return; }