diff --git a/lib/datasource/github-tags/index.spec.ts b/lib/datasource/github-tags/index.spec.ts index 430e3d4a8bc21db024047d93be100097c464f05f..8fb288b9790e90238a8c58e89ade49860bd4a593 100644 --- a/lib/datasource/github-tags/index.spec.ts +++ b/lib/datasource/github-tags/index.spec.ts @@ -1,5 +1,6 @@ import { api } from '../../platform/github/gh-got-wrapper'; import * as globalCache from '../../util/cache/global'; +import * as runCache from '../../util/cache/run'; import * as _hostRules from '../../util/host-rules'; import * as github from '.'; @@ -16,6 +17,7 @@ describe('datasource/github-tags', () => { beforeEach(() => { jest.resetAllMocks(); hostRules.hosts = jest.fn(() => []); + runCache.clear(); return globalCache.rmAll(); }); it('returns null if no token', async () => { diff --git a/lib/datasource/helm/__snapshots__/index.spec.ts.snap b/lib/datasource/helm/__snapshots__/index.spec.ts.snap index e29bfcf08e6e7ca6b8766b0d61c8460c79e99b48..11e2ce569c934ea90c91b4584870e3dcbeae0491 100644 --- a/lib/datasource/helm/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/helm/__snapshots__/index.spec.ts.snap @@ -1,123 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`datasource/helm getReleases returns list of versions for normal response if index.yaml is cached 1`] = ` -Object { - "homepage": "https://www.getambassador.io/", - "name": "ambassador", - "releases": Array [ - Object { - "releaseTimestamp": "2019-06-02T08:56:36.119Z", - "version": "2.7.0", - }, - Object { - "releaseTimestamp": "2019-05-31T18:57:01.540Z", - "version": "2.6.2", - }, - Object { - "releaseTimestamp": "2019-05-27T23:28:25.443Z", - "version": "2.6.1", - }, - Object { - "releaseTimestamp": "2019-05-24T10:56:37.781Z", - "version": "2.6.0", - }, - Object { - "releaseTimestamp": "2019-05-20T23:56:32.309Z", - "version": "2.5.1", - }, - Object { - "releaseTimestamp": "2019-05-16T21:56:48.001Z", - "version": "2.5.0", - }, - Object { - "releaseTimestamp": "2019-05-15T07:56:25.942Z", - "version": "2.4.1", - }, - Object { - "releaseTimestamp": "2019-05-09T17:29:35.612Z", - "version": "2.4.0", - }, - Object { - "releaseTimestamp": "2019-05-08T19:26:25.925Z", - "version": "2.3.1", - }, - Object { - "releaseTimestamp": "2019-05-06T21:28:21.342Z", - "version": "2.3.0", - }, - Object { - "releaseTimestamp": "2019-05-06T20:56:39.732Z", - "version": "2.2.5", - }, - Object { - "releaseTimestamp": "2019-05-01T19:56:23.829Z", - "version": "2.2.4", - }, - Object { - "releaseTimestamp": "2019-05-01T14:27:55.475Z", - "version": "2.2.3", - }, - Object { - "releaseTimestamp": "2019-04-29T20:56:20.987Z", - "version": "2.2.2", - }, - Object { - "releaseTimestamp": "2019-04-27T01:56:41.147Z", - "version": "2.2.1", - }, - Object { - "releaseTimestamp": "2019-04-23T19:56:09.380Z", - "version": "2.2.0", - }, - Object { - "releaseTimestamp": "2019-04-23T14:57:59.089Z", - "version": "2.1.0", - }, - Object { - "releaseTimestamp": "2019-04-08T13:26:12.863Z", - "version": "2.0.2", - }, - Object { - "releaseTimestamp": "2019-04-06T13:26:04.916Z", - "version": "2.0.1", - }, - Object { - "releaseTimestamp": "2019-03-22T14:26:18.094Z", - "version": "2.0.0", - }, - Object { - "releaseTimestamp": "2019-03-21T15:25:53.910Z", - "version": "1.1.5", - }, - Object { - "releaseTimestamp": "2019-02-24T04:55:38.454Z", - "version": "1.1.4", - }, - Object { - "releaseTimestamp": "2019-02-22T16:28:27.398Z", - "version": "1.1.3", - }, - Object { - "releaseTimestamp": "2019-02-15T23:56:28.304Z", - "version": "1.1.2", - }, - Object { - "releaseTimestamp": "2019-02-14T16:55:51.519Z", - "version": "1.1.1", - }, - Object { - "releaseTimestamp": "2019-02-14T15:25:43.743Z", - "version": "1.1.0", - }, - Object { - "releaseTimestamp": "2019-02-13T00:56:01.476Z", - "version": "1.0.0", - }, - ], - "sourceUrl": "https://github.com/datawire/ambassador", -} -`; - exports[`datasource/helm getReleases returns list of versions for normal response if index.yaml is not cached 1`] = ` Object { "homepage": "https://www.getambassador.io/", diff --git a/lib/datasource/helm/index.spec.ts b/lib/datasource/helm/index.spec.ts index 520e12433c48e67f5cc3489c1b9535cdc68bf239..466e870d2669f5e114692408c0713f31a5000683 100644 --- a/lib/datasource/helm/index.spec.ts +++ b/lib/datasource/helm/index.spec.ts @@ -1,7 +1,8 @@ import fs from 'fs'; import * as globalCache from '../../util/cache/global'; +import * as runCache from '../../util/cache/run'; import _got from '../../util/got'; -import { getReleases, getRepositoryData } from '.'; +import { getReleases } from '.'; const got: any = _got; @@ -17,6 +18,7 @@ describe('datasource/helm', () => { describe('getReleases', () => { beforeEach(() => { jest.resetAllMocks(); + runCache.clear(); return globalCache.rmAll(); }); it('returns null if lookupName was not provided', async () => { @@ -137,25 +139,5 @@ describe('datasource/helm', () => { expect(releases).not.toBeNull(); expect(releases).toMatchSnapshot(); }); - it('returns list of versions for normal response if index.yaml is cached', async () => { - const repository = 'example-repository.com'; - const cacheNamespace = 'datasource-helm'; - const cacheKey = repository; - const cacheMinutes = 10; - got.mockReturnValueOnce({ body: indexYaml }); - const repositoryData = await getRepositoryData(repository); - await globalCache.set( - cacheNamespace, - cacheKey, - repositoryData, - cacheMinutes - ); - const releases = await getReleases({ - lookupName: 'ambassador', - registryUrls: [repository], - }); - expect(releases).not.toBeNull(); - expect(releases).toMatchSnapshot(); - }); }); }); diff --git a/lib/datasource/helm/index.ts b/lib/datasource/helm/index.ts index e1eed39e5eb359aab23818476b4898942aaf53f0..1c8df70e3eaefe6bcbe10ad75cb16ea6f4412982 100644 --- a/lib/datasource/helm/index.ts +++ b/lib/datasource/helm/index.ts @@ -15,6 +15,7 @@ export async function getRepositoryData( const cacheNamespace = 'datasource-helm'; const cacheKey = repository; const cachedIndex = await globalCache.get(cacheNamespace, cacheKey); + // istanbul ignore if if (cachedIndex) { return cachedIndex; } diff --git a/lib/datasource/nuget/index.spec.ts b/lib/datasource/nuget/index.spec.ts index f980d8ee6e57ee1c0d7c15e591b68f7a2913115e..811f49e3642d70dd4b02259a12ebd83de734449a 100644 --- a/lib/datasource/nuget/index.spec.ts +++ b/lib/datasource/nuget/index.spec.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import * as globalCache from '../../util/cache/global'; +import * as runCache from '../../util/cache/run'; import _got from '../../util/got'; import * as _hostRules from '../../util/host-rules'; import * as nuget from '.'; @@ -83,7 +84,10 @@ const configV3NotNugetOrg = { }; describe('datasource/nuget', () => { - beforeEach(() => globalCache.rmAll()); + beforeEach(() => { + runCache.clear(); + return globalCache.rmAll(); + }); describe('getReleases', () => { beforeEach(() => { jest.resetAllMocks(); diff --git a/lib/datasource/orb/index.spec.ts b/lib/datasource/orb/index.spec.ts index 52606fce0a7ae71799badb54045c4226b63ea376..8a2c1a442c7c790c6da1a8de28ec91709e830f37 100644 --- a/lib/datasource/orb/index.spec.ts +++ b/lib/datasource/orb/index.spec.ts @@ -1,4 +1,5 @@ import * as globalCache from '../../util/cache/global'; +import * as runCache from '../../util/cache/run'; import _got from '../../util/got'; import * as datasource from '.'; @@ -31,6 +32,7 @@ describe('datasource/orb', () => { describe('getReleases', () => { beforeEach(() => { jest.clearAllMocks(); + runCache.clear(); return globalCache.rmAll(); }); it('returns null for empty result', async () => { diff --git a/lib/datasource/ruby-version/index.spec.ts b/lib/datasource/ruby-version/index.spec.ts index f99b8eaef9adb08f8534f7ee6b4f1c4a09e40a20..abf17da1ec1e653b81749764aa8cbc2dd3db022a 100644 --- a/lib/datasource/ruby-version/index.spec.ts +++ b/lib/datasource/ruby-version/index.spec.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import * as globalCache from '../../util/cache/global'; +import * as runCache from '../../util/cache/run'; import _got from '../../util/got'; import { getReleases } from '.'; @@ -15,6 +16,7 @@ const rubyReleasesHtml = fs.readFileSync( describe('datasource/gradle', () => { describe('getReleases', () => { beforeEach(() => { + runCache.clear(); return globalCache.rmAll(); }); it('parses real data', async () => { diff --git a/lib/util/cache/global.ts b/lib/util/cache/global.ts index 5f3a8e6db12c704783979fe5b82a192b9a0e558c..326d27925dc83c6fa80b04f3219ca262f36dfb6f 100644 --- a/lib/util/cache/global.ts +++ b/lib/util/cache/global.ts @@ -1,5 +1,15 @@ +import * as runCache from './run'; + +function getGlobalKey(namespace: string, key: string): string { + return `global%%${namespace}%%${key}`; +} + export function get<T = any>(namespace: string, key: string): Promise<T> { - return renovateCache.get(namespace, key); + const globalKey = getGlobalKey(namespace, key); + if (!runCache.get(globalKey)) { + runCache.set(globalKey, renovateCache.get(namespace, key)); + } + return runCache.get(globalKey); } export function set( @@ -8,6 +18,8 @@ export function set( value: any, minutes: number ): Promise<void> { + const globalKey = getGlobalKey(namespace, key); + runCache.set(globalKey, value); return renovateCache.set(namespace, key, value, minutes); } diff --git a/lib/workers/pr/changelog/index.spec.ts b/lib/workers/pr/changelog/index.spec.ts index 788e4e99cbd006b3f8f86ca4ab209e626a9cd097..7ad98cb885725dffc2db57eb07d4f04ac397a326 100644 --- a/lib/workers/pr/changelog/index.spec.ts +++ b/lib/workers/pr/changelog/index.spec.ts @@ -2,6 +2,7 @@ import { mocked, partial } from '../../../../test/util'; import { PLATFORM_TYPE_GITHUB } from '../../../constants/platforms'; import { api } from '../../../platform/github/gh-got-wrapper'; import * as globalCache from '../../../util/cache/global'; +import * as runCache from '../../../util/cache/run'; import * as hostRules from '../../../util/host-rules'; import * as semverVersioning from '../../../versioning/semver'; import { BranchConfig } from '../../common'; @@ -44,6 +45,7 @@ describe('workers/pr/changelog', () => { token: 'abc', }); await globalCache.rmAll(); + runCache.clear(); }); it('returns null if @types', async () => { expect(