diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index 5f57ff5212e93b..f72124f0233706 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -327,6 +327,10 @@ Results which are soft expired are reused in the following manner: - The `etag` from the cached results will be reused, and may result in a 304 response, meaning cached results are revalidated - If an error occurs when querying the `npmjs` registry, then soft expired results will be reused if they are present +## cachePrivatePackages + +In the self-hosted setup, use option to enable caching of private packages to improve performance. + ## cacheTtlOverride Utilize this key-value map to override the default package cache TTL values for a specific namespace. This object contains pairs of namespaces and their corresponding TTL values in minutes. diff --git a/lib/config/global.ts b/lib/config/global.ts index 3008fb6117f004..b1b1205dbd50cd 100644 --- a/lib/config/global.ts +++ b/lib/config/global.ts @@ -37,6 +37,7 @@ export class GlobalConfig { 'autodiscoverRepoSort', 'autodiscoverRepoOrder', 'userAgent', + 'cachePrivatePackages', ]; private static config: RepoGlobalConfig = {}; diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 627efe28c3f0f9..3bec15eefb2d24 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -3117,6 +3117,14 @@ const options: RenovateOptions[] = [ default: 90, globalOnly: true, }, + { + name: 'cachePrivatePackages', + description: + 'Cache private packages in the datasource cache. This is useful for self-hosted setups', + type: 'boolean', + default: false, + globalOnly: true, + }, ]; export function getOptions(): RenovateOptions[] { diff --git a/lib/config/types.ts b/lib/config/types.ts index f62e4d2484e458..796731ebc1e693 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -166,6 +166,7 @@ export interface RepoGlobalConfig { autodiscoverRepoSort?: RepoSortMethod; autodiscoverRepoOrder?: SortMethod; userAgent?: string; + cachePrivatePackages?: boolean; } export interface LegacyAdminConfig { diff --git a/lib/util/cache/package/decorator.spec.ts b/lib/util/cache/package/decorator.spec.ts index c8716c410f3313..2cf76c495a1b98 100644 --- a/lib/util/cache/package/decorator.spec.ts +++ b/lib/util/cache/package/decorator.spec.ts @@ -67,6 +67,29 @@ describe('util/cache/package/decorator', () => { expect(setCache).not.toHaveBeenCalled(); }); + it('forces cache if cachePrivatePackages=true', async () => { + GlobalConfig.set({ cachePrivatePackages: true }); + + class Class { + @cache({ + namespace: '_test-namespace', + key: 'key', + cacheable: () => false, + }) + public fn(): Promise { + return getValue(); + } + } + const obj = new Class(); + + expect(await obj.fn()).toBe('111'); + expect(await obj.fn()).toBe('111'); + expect(await obj.fn()).toBe('111'); + + expect(getValue).toHaveBeenCalledTimes(1); + expect(setCache).toHaveBeenCalledOnce(); + }); + it('caches null values', async () => { class Class { @cache({ namespace: '_test-namespace', key: 'key' }) diff --git a/lib/util/cache/package/decorator.ts b/lib/util/cache/package/decorator.ts index f81d01895dbee7..052ac79c79d349 100644 --- a/lib/util/cache/package/decorator.ts +++ b/lib/util/cache/package/decorator.ts @@ -50,7 +50,12 @@ export function cache({ ttlMinutes = 30, }: CacheParameters): Decorator { return decorate(async ({ args, instance, callback, methodName }) => { - if (!cacheable.apply(instance, args)) { + const cachePrivatePackages = GlobalConfig.get( + 'cachePrivatePackages', + false, + ); + const isCacheable = cachePrivatePackages || cacheable.apply(instance, args); + if (!isCacheable) { return callback(); }