Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename globalCache to packageCache #6580

Merged
merged 2 commits into from Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/datasource/cache.ts
@@ -1,5 +1,5 @@
import { logger } from '../logger';
import * as globalCache from '../util/cache/global';
import * as packageCache from '../util/cache/package';

/**
* Cache callback result which has to be returned by the `CacheCallback` function.
Expand Down Expand Up @@ -58,7 +58,10 @@ export async function cacheAble<TArg, TResult = unknown>({
}: CacheConfig<TArg, TResult>): Promise<TResult> {
const cacheNamespace = `datasource-${id}`;
const cacheKey = JSON.stringify(lookup);
const cachedResult = await globalCache.get<TResult>(cacheNamespace, cacheKey);
const cachedResult = await packageCache.get<TResult>(
cacheNamespace,
cacheKey
);
// istanbul ignore if
if (cachedResult) {
logger.trace({ id, lookup }, 'datasource cachedResult');
Expand All @@ -69,7 +72,7 @@ export async function cacheAble<TArg, TResult = unknown>({
if (isPrivate) {
logger.trace({ id, lookup }, 'Skipping datasource cache for private data');
} else {
await globalCache.set(cacheNamespace, cacheKey, data, minutes);
await packageCache.set(cacheNamespace, cacheKey, data, minutes);
}
return data;
}
6 changes: 3 additions & 3 deletions lib/datasource/crate/index.ts
@@ -1,6 +1,6 @@
import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import { Http } from '../../util/http';
import { GetReleasesConfig, Release, ReleaseResult } from '../common';

Expand All @@ -13,7 +13,7 @@ export async function getReleases({
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const cacheNamespace = 'datasource-crate';
const cacheKey = lookupName;
const cachedResult = await globalCache.get<ReleaseResult>(
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
cacheKey
);
Expand Down Expand Up @@ -63,7 +63,7 @@ export async function getReleases({
return null;
}
const cacheMinutes = 10;
await globalCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
return result;
} catch (err) {
if (err.statusCode === 404 || err.code === 'ENOTFOUND') {
Expand Down
14 changes: 7 additions & 7 deletions lib/datasource/docker/index.ts
Expand Up @@ -7,7 +7,7 @@ import wwwAuthenticate from 'www-authenticate';
import { logger } from '../../logger';
import { HostRule } from '../../types';
import { ExternalHostError } from '../../types/errors/external-host-error';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import * as hostRules from '../../util/host-rules';
import { Http, HttpResponse } from '../../util/http';
import { GetReleasesConfig, ReleaseResult } from '../common';
Expand Down Expand Up @@ -342,7 +342,7 @@ export async function getDigest(
const cacheKey = `${registry}:${repository}:${newTag}`;
let digest = null;
try {
const cachedResult = await globalCache.get(cacheNamespace, cacheKey);
const cachedResult = await packageCache.get(cacheNamespace, cacheKey);
// istanbul ignore if
if (cachedResult !== undefined) {
return cachedResult;
Expand Down Expand Up @@ -370,7 +370,7 @@ export async function getDigest(
);
}
const cacheMinutes = 30;
await globalCache.set(cacheNamespace, cacheKey, digest, cacheMinutes);
await packageCache.set(cacheNamespace, cacheKey, digest, cacheMinutes);
return digest;
}

Expand All @@ -382,7 +382,7 @@ async function getTags(
try {
const cacheNamespace = 'datasource-docker-tags';
const cacheKey = `${registry}:${repository}`;
const cachedResult = await globalCache.get<string[]>(
const cachedResult = await packageCache.get<string[]>(
cacheNamespace,
cacheKey
);
Expand Down Expand Up @@ -411,7 +411,7 @@ async function getTags(
page += 1;
} while (url && page < 20);
const cacheMinutes = 15;
await globalCache.set(cacheNamespace, cacheKey, tags, cacheMinutes);
await packageCache.set(cacheNamespace, cacheKey, tags, cacheMinutes);
return tags;
} catch (err) /* istanbul ignore next */ {
if (err instanceof ExternalHostError) {
Expand Down Expand Up @@ -482,7 +482,7 @@ async function getLabels(
logger.debug(`getLabels(${registry}, ${repository}, ${tag})`);
const cacheNamespace = 'datasource-docker-labels';
const cacheKey = `${registry}:${repository}:${tag}`;
const cachedResult = await globalCache.get<Record<string, string>>(
const cachedResult = await packageCache.get<Record<string, string>>(
cacheNamespace,
cacheKey
);
Expand Down Expand Up @@ -541,7 +541,7 @@ async function getLabels(
);
}
const cacheMinutes = 60;
await globalCache.set(cacheNamespace, cacheKey, labels, cacheMinutes);
await packageCache.set(cacheNamespace, cacheKey, labels, cacheMinutes);
return labels;
} catch (err) {
if (err instanceof ExternalHostError) {
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/galaxy/index.ts
@@ -1,6 +1,6 @@
import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import { Http } from '../../util/http';
import { GetReleasesConfig, Release, ReleaseResult } from '../common';

Expand All @@ -13,7 +13,7 @@ export async function getReleases({
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const cacheNamespace = 'datasource-galaxy';
const cacheKey = lookupName;
const cachedResult = await globalCache.get<ReleaseResult>(
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
cacheKey
);
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function getReleases({
}
);
const cacheMinutes = 10;
await globalCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
return result;
} catch (err) {
if (
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/git-refs/index.ts
@@ -1,6 +1,6 @@
import simpleGit from 'simple-git/promise';
import { logger } from '../../logger';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import * as semver from '../../versioning/semver';
import { DigestConfig, GetReleasesConfig, ReleaseResult } from '../common';

Expand All @@ -24,7 +24,7 @@ export async function getRawRefs({
try {
const cacheNamespace = 'git-raw-refs';

const cachedResult = await globalCache.get<RawRefs[]>(
const cachedResult = await packageCache.get<RawRefs[]>(
cacheNamespace,
lookupName
);
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function getRawRefs({
})
.filter(Boolean)
.filter((ref) => ref.type !== 'pull' && !ref.value.endsWith('^{}'));
await globalCache.set(cacheNamespace, lookupName, refs, cacheMinutes);
await packageCache.set(cacheNamespace, lookupName, refs, cacheMinutes);
return refs;
} catch (err) {
logger.info({ err }, `Git-Raw-Refs lookup error in ${lookupName}`);
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/git-submodules/index.ts
Expand Up @@ -2,7 +2,7 @@ import { URL } from 'url';
import Git from 'simple-git/promise';

import { logger } from '../../logger';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import { DigestConfig, GetReleasesConfig, ReleaseResult } from '../common';

export const id = 'git-submodules';
Expand All @@ -13,7 +13,7 @@ export async function getReleases({
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const cacheNamespace = 'datasource-git-submodules';
const cacheKey = `${registryUrls[0]}-${registryUrls[1]}`;
const cachedResult = await globalCache.get<ReleaseResult>(
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
cacheKey
);
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function getReleases({
],
};
const cacheMinutes = 60;
await globalCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
return result;
} catch (err) {
logger.debug({ err }, `Git-SubModules lookup error in ${lookupName}`);
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/github-releases/index.ts
@@ -1,5 +1,5 @@
import { logger } from '../../logger';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import { GithubHttp } from '../../util/http/github';
import { GetReleasesConfig, ReleaseResult } from '../common';

Expand Down Expand Up @@ -28,7 +28,7 @@ export async function getReleases({
lookupName: repo,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
let githubReleases: GithubRelease[];
const cachedResult = await globalCache.get<ReleaseResult>(
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
repo
);
Expand Down Expand Up @@ -59,6 +59,6 @@ export async function getReleases({
releaseTimestamp: published_at,
}));
const cacheMinutes = 10;
await globalCache.set(cacheNamespace, repo, dependency, cacheMinutes);
await packageCache.set(cacheNamespace, repo, dependency, cacheMinutes);
return dependency;
}
14 changes: 7 additions & 7 deletions lib/datasource/github-tags/index.ts
@@ -1,5 +1,5 @@
import { logger } from '../../logger';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import { GithubHttp } from '../../util/http/github';
import { DigestConfig, GetReleasesConfig, ReleaseResult } from '../common';

Expand All @@ -24,7 +24,7 @@ async function getTagCommit(
githubRepo: string,
tag: string
): Promise<string | null> {
const cachedResult = await globalCache.get<string>(
const cachedResult = await packageCache.get<string>(
cacheNamespace,
getCacheKey(githubRepo, `tag-${tag}`)
);
Expand Down Expand Up @@ -53,7 +53,7 @@ async function getTagCommit(
return null;
}
const cacheMinutes = 120;
await globalCache.set(
await packageCache.set(
cacheNamespace,
getCacheKey(githubRepo, `tag-${tag}`),
digest,
Expand All @@ -76,7 +76,7 @@ export async function getDigest(
if (newValue && newValue.length) {
return getTagCommit(githubRepo, newValue);
}
const cachedResult = await globalCache.get(
const cachedResult = await packageCache.get(
cacheNamespace,
getCacheKey(githubRepo, 'commit')
);
Expand All @@ -99,7 +99,7 @@ export async function getDigest(
return null;
}
const cacheMinutes = 10;
await globalCache.set(
await packageCache.set(
cacheNamespace,
getCacheKey(githubRepo, 'commit'),
digest,
Expand All @@ -122,7 +122,7 @@ export async function getReleases({
lookupName: repo,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
let versions: string[];
const cachedResult = await globalCache.get<ReleaseResult>(
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
getCacheKey(repo, 'tags')
);
Expand Down Expand Up @@ -157,7 +157,7 @@ export async function getReleases({
gitRef: version,
}));
const cacheMinutes = 10;
await globalCache.set(
await packageCache.set(
cacheNamespace,
getCacheKey(repo, 'tags'),
dependency,
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/gitlab-tags/index.ts
@@ -1,6 +1,6 @@
import URL from 'url';
import { logger } from '../../logger';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import { GitlabHttp } from '../../util/http/gitlab';
import { GetReleasesConfig, ReleaseResult } from '../common';

Expand Down Expand Up @@ -28,7 +28,7 @@ export async function getReleases({
lookupName: repo,
}: GetReleasesConfig): Promise<ReleaseResult | null> {
let gitlabTags: GitlabTag[];
const cachedResult = await globalCache.get<ReleaseResult>(
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
getCacheKey(depHost, repo)
);
Expand Down Expand Up @@ -72,7 +72,7 @@ export async function getReleases({
}));

const cacheMinutes = 10;
await globalCache.set(
await packageCache.set(
cacheNamespace,
getCacheKey(depHost, repo),
dependency,
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/helm/index.ts
Expand Up @@ -2,7 +2,7 @@ import yaml from 'js-yaml';

import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import { Http } from '../../util/http';
import { ensureTrailingSlash } from '../../util/url';
import { GetReleasesConfig, ReleaseResult } from '../common';
Expand All @@ -21,7 +21,7 @@ export async function getRepositoryData(
): Promise<ReleaseResult[]> {
const cacheNamespace = 'datasource-helm';
const cacheKey = repository;
const cachedIndex = await globalCache.get(cacheNamespace, cacheKey);
const cachedIndex = await packageCache.get(cacheNamespace, cacheKey);
// istanbul ignore if
if (cachedIndex) {
return cachedIndex;
Expand Down Expand Up @@ -92,7 +92,7 @@ export async function getRepositoryData(
})
);
const cacheMinutes = 20;
await globalCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
return result;
} catch (err) {
logger.warn(`Failed to parse index.yaml from ${repository}`);
Expand Down
10 changes: 5 additions & 5 deletions lib/datasource/maven/index.ts
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs-extra';
import pAll from 'p-all';
import { XmlDocument } from 'xmldoc';
import { logger } from '../../logger';
import * as globalCache from '../../util/cache/global';
import * as packageCache from '../../util/cache/package';
import mavenVersion from '../../versioning/maven';
import { compare } from '../../versioning/maven/compare';
import { GetReleasesConfig, ReleaseResult } from '../common';
Expand Down Expand Up @@ -158,7 +158,7 @@ async function getVersionsFromMetadata(

const cacheNamespace = 'datasource-maven-metadata';
const cacheKey = metadataUrl.toString();
const cachedVersions = await globalCache.get<string[]>(
const cachedVersions = await packageCache.get<string[]>(
cacheNamespace,
cacheKey
);
Expand All @@ -173,7 +173,7 @@ async function getVersionsFromMetadata(
}

const versions = extractVersions(mavenMetadata);
await globalCache.set(cacheNamespace, cacheKey, versions, 10);
await packageCache.set(cacheNamespace, cacheKey, versions, 10);
return versions;
}

Expand Down Expand Up @@ -211,7 +211,7 @@ async function filterMissingArtifacts(
): Promise<string[]> {
const cacheNamespace = 'datasource-maven-metadata';
const cacheKey = dependency.dependencyUrl;
let artifactsInfo: ArtifactsInfo | null = await globalCache.get<
let artifactsInfo: ArtifactsInfo | null = await packageCache.get<
ArtifactsInfo
>(cacheNamespace, cacheKey);

Expand Down Expand Up @@ -243,7 +243,7 @@ async function filterMissingArtifacts(
? 60
: 24 * 60;

await globalCache.set(cacheNamespace, cacheKey, artifactsInfo, cacheTTL);
await packageCache.set(cacheNamespace, cacheKey, artifactsInfo, cacheTTL);
}

return versions.filter((v) => artifactsInfo[v]);
Expand Down