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

fix: Use globally-set hard TTL for package cache #24116

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/config/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,7 @@ const options: RenovateOptions[] = [
'Maximum duration in minutes to keep datasource cache entries.',
type: 'integer',
stage: 'repository',
default: 24 * 60,
default: 7 * 24 * 60,
globalOnly: true,
},
{
Expand Down
2 changes: 1 addition & 1 deletion lib/util/cache/package/decorator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ describe('util/cache/package/decorator', () => {
namespace: 'namespace',
key: 'key',
ttlMinutes: 1,
fallbackTtlMinutes: 2,
})

// Hard TTL is enabled only for `getReleases` and `getDigest` methods
Expand All @@ -172,6 +171,7 @@ describe('util/cache/package/decorator', () => {

beforeEach(() => {
jest.useFakeTimers({ advanceTimers: false });
GlobalConfig.set({ cacheHardTtlMinutes: 2 });
});

afterEach(() => {
Expand Down
14 changes: 5 additions & 9 deletions lib/util/cache/package/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ interface CacheParameters {
* The TTL (or expiry) of the key in minutes
*/
ttlMinutes?: number;

/**
* Store cached results for this many minutes after the TTL has expired,
* in case if the errors were thrown during obtaining the new results.
*/
fallbackTtlMinutes?: number;
}

/**
Expand All @@ -51,7 +45,6 @@ export function cache<T>({
key,
cacheable = () => true,
ttlMinutes = 30,
fallbackTtlMinutes = 0,
}: CacheParameters): Decorator<T> {
return decorate(async ({ args, instance, callback, methodName }) => {
if (!cacheable.apply(instance, args)) {
Expand Down Expand Up @@ -86,10 +79,13 @@ export function cache<T>({
const ttlOverride = getTtlOverride(finalNamespace);
const softTtl = ttlOverride ?? ttlMinutes;

const globalFallbackTtlMinutes = GlobalConfig.get('cacheHardTtlMinutes', 0);
const cacheHardTtlMinutes = GlobalConfig.get(
'cacheHardTtlMinutes',
7 * 24 * 60
);
let hardTtl = softTtl;
if (methodName === 'getReleases' || methodName === 'getDigest') {
hardTtl = Math.max(softTtl, fallbackTtlMinutes, globalFallbackTtlMinutes);
hardTtl = Math.max(softTtl, cacheHardTtlMinutes);
}

let oldData: unknown;
Expand Down