Skip to content

Commit

Permalink
feat: Support cachePrivatePackages option for datasource index level (
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Jul 12, 2024
1 parent 8d166a3 commit 4aca729
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/modules/datasource/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import is from '@sindresorhus/is';
import { dequal } from 'dequal';
import { GlobalConfig } from '../../config/global';
import { HOST_DISABLED } from '../../constants/error-messages';
import { logger } from '../../logger';
import { ExternalHostError } from '../../types/errors/external-host-error';
Expand Down Expand Up @@ -79,10 +80,16 @@ async function getRegistryReleases(
res.registryUrl ??= registryUrl;
}
// cache non-null responses unless marked as private
if (datasource.caching && res && !res.isPrivate) {
logger.trace({ cacheKey }, 'Caching datasource response');
const cacheMinutes = 15;
await packageCache.set(cacheNamespace, cacheKey, res, cacheMinutes);
if (datasource.caching && res) {
const cachePrivatePackages = GlobalConfig.get(
'cachePrivatePackages',
false,
);
if (cachePrivatePackages || !res.isPrivate) {
logger.trace({ cacheKey }, 'Caching datasource response');
const cacheMinutes = 15;
await packageCache.set(cacheNamespace, cacheKey, res, cacheMinutes);
}
}
return res;
}
Expand Down

0 comments on commit 4aca729

Please sign in to comment.