Skip to content

Commit

Permalink
fix(terraform-provider): reintroduce caching (#6724)
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor committed Jul 10, 2020
1 parent fc2cd93 commit db698b5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/datasource/terraform-provider/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import URL from 'url';
import { logger } from '../../logger';
import * as packageCache from '../../util/cache/package';
import { Http } from '../../util/http';
import { GetReleasesConfig, ReleaseResult } from '../common';

Expand Down Expand Up @@ -88,6 +89,17 @@ export async function getReleases({
}: GetReleasesConfig): Promise<ReleaseResult | null> {
const repository = `hashicorp/${lookupName}`;

const cacheNamespace = 'terraform-provider';
const pkgUrl = `${registryUrl}/${repository}`;
const cachedResult = await packageCache.get<ReleaseResult>(
cacheNamespace,
pkgUrl
);
// istanbul ignore if
if (cachedResult) {
return cachedResult;
}

logger.debug({ lookupName }, 'terraform-provider.getDependencies()');
let dep: ReleaseResult = null;
const registryHost = URL.parse(registryUrl).host;
Expand All @@ -96,5 +108,7 @@ export async function getReleases({
} else if (registryHost === 'releases.hashicorp.com') {
dep = await queryReleaseBackend(lookupName, registryUrl, repository);
}
const cacheMinutes = 30;
await packageCache.set(cacheNamespace, pkgUrl, dep, cacheMinutes);
return dep;
}

0 comments on commit db698b5

Please sign in to comment.