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

feat: Add cachePrivatePackages global config option #30045

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/usage/self-hosted-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/config/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class GlobalConfig {
'autodiscoverRepoSort',
'autodiscoverRepoOrder',
'userAgent',
'cachePrivatePackages',
];

private static config: RepoGlobalConfig = {};
Expand Down
8 changes: 8 additions & 0 deletions lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down
1 change: 1 addition & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export interface RepoGlobalConfig {
autodiscoverRepoSort?: RepoSortMethod;
autodiscoverRepoOrder?: SortMethod;
userAgent?: string;
cachePrivatePackages?: boolean;
}

export interface LegacyAdminConfig {
Expand Down
23 changes: 23 additions & 0 deletions lib/util/cache/package/decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null> {
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' })
Expand Down
7 changes: 6 additions & 1 deletion lib/util/cache/package/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export function cache<T>({
ttlMinutes = 30,
}: CacheParameters): Decorator<T> {
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();
}

Expand Down