mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat: Add cachePrivatePackages
global config option (#30045)
This commit is contained in:
parent
c55dc8e4ec
commit
8fc2a7bdb2
6 changed files with 43 additions and 1 deletions
|
@ -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.
|
||||
|
|
|
@ -37,6 +37,7 @@ export class GlobalConfig {
|
|||
'autodiscoverRepoSort',
|
||||
'autodiscoverRepoOrder',
|
||||
'userAgent',
|
||||
'cachePrivatePackages',
|
||||
];
|
||||
|
||||
private static config: RepoGlobalConfig = {};
|
||||
|
|
|
@ -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[] {
|
||||
|
|
|
@ -166,6 +166,7 @@ export interface RepoGlobalConfig {
|
|||
autodiscoverRepoSort?: RepoSortMethod;
|
||||
autodiscoverRepoOrder?: SortMethod;
|
||||
userAgent?: string;
|
||||
cachePrivatePackages?: boolean;
|
||||
}
|
||||
|
||||
export interface LegacyAdminConfig {
|
||||
|
|
23
lib/util/cache/package/decorator.spec.ts
vendored
23
lib/util/cache/package/decorator.spec.ts
vendored
|
@ -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' })
|
||||
|
|
7
lib/util/cache/package/decorator.ts
vendored
7
lib/util/cache/package/decorator.ts
vendored
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue