diff --git a/lib/modules/datasource/github-releases/cache/cache-base.ts b/lib/modules/datasource/github-releases/cache/cache-base.ts index 998c3164d83d9c9345a958812149f3009f8dd507..a5a7d27fb1aa36fc2da248a9c264988d2247b956 100644 --- a/lib/modules/datasource/github-releases/cache/cache-base.ts +++ b/lib/modules/datasource/github-releases/cache/cache-base.ts @@ -1,5 +1,6 @@ import { DateTime, DurationLikeObject } from 'luxon'; import { logger } from '../../../../logger'; +import * as memCache from '../../../../util/cache/memory'; import * as packageCache from '../../../../util/cache/package'; import type { GithubGraphqlResponse, @@ -184,10 +185,25 @@ export abstract class AbstractGithubDatasourceCache< } } + private getBaseUrl(registryUrl: string | undefined): string { + const baseUrl = getApiBaseUrl(registryUrl).replace(/\/v3\/$/, '/'); // Replace for GHE + return baseUrl; + } + + private getCacheKey( + registryUrl: string | undefined, + packageName: string + ): string { + const baseUrl = this.getBaseUrl(registryUrl); + const [owner, name] = packageName.split('/'); + const cacheKey = `${baseUrl}:${owner}:${name}`; + return cacheKey; + } + /** * Pre-fetch, update, or just return the package cache items. */ - async getItems( + async getItemsImpl( releasesConfig: GetReleasesConfig, changelogRelease?: ChangelogRelease ): Promise<StoredItem[]> { @@ -208,11 +224,10 @@ export abstract class AbstractGithubDatasourceCache< // so that soft update mechanics is immediately starting. let cacheUpdatedAt = now.minus(this.updateDuration).toISO(); - const baseUrl = getApiBaseUrl(registryUrl).replace(/\/v3\/$/, '/'); // Replace for GHE - const [owner, name] = packageName.split('/'); if (owner && name) { - const cacheKey = `${baseUrl}:${owner}:${name}`; + const baseUrl = this.getBaseUrl(registryUrl); + const cacheKey = this.getCacheKey(registryUrl, packageName); const cache = await packageCache.get<GithubDatasourceCache<StoredItem>>( this.cacheNs, cacheKey @@ -379,6 +394,20 @@ export abstract class AbstractGithubDatasourceCache< return items; } + getItems( + releasesConfig: GetReleasesConfig, + changelogRelease?: ChangelogRelease + ): Promise<StoredItem[]> { + const { packageName, registryUrl } = releasesConfig; + const cacheKey = this.getCacheKey(registryUrl, packageName); + const promiseKey = `github-datasource-cache:${this.cacheNs}:${cacheKey}`; + const res = + memCache.get<Promise<StoredItem[]>>(promiseKey) ?? + this.getItemsImpl(releasesConfig, changelogRelease); + memCache.set(promiseKey, res); + return res; + } + getRandomDeltaMinutes(): number { const rnd = Math.random(); return Math.floor(rnd * this.resetDeltaMinutes);