Skip to content

Commit

Permalink
fix: Use globally-set hard TTL for package cache (#24116)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov committed Aug 27, 2023
1 parent 9c322cd commit 6636b7c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/config/options/index.ts
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
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
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

0 comments on commit 6636b7c

Please sign in to comment.