import * as packageCache from '../../../cache/package/index.ts'; import type { GithubDatasourceItem, GithubGraphqlCacheRecord, } from '../types.ts'; import { AbstractGithubGraphqlCacheStrategy } from './abstract-cache-strategy.ts'; /** * Package cache strategy meant to be used for public packages. */ export class GithubGraphqlPackageCacheStrategy< GithubItem extends GithubDatasourceItem, > extends AbstractGithubGraphqlCacheStrategy { load(): Promise | undefined> { return packageCache.get(this.cacheNs, this.cacheKey); } async persist( cacheRecord: GithubGraphqlCacheRecord, ): Promise { const expiry = this.createdAt .plus({ // Not using 'days' as it does not handle adjustments for Daylight Saving time. // The offset in the resulting DateTime object does not match that of the expiry or this.now. hours: AbstractGithubGraphqlCacheStrategy.cacheTTLDays * 24, }) .toUTC(); const ttlMinutes = expiry.diff(this.now, ['minutes']).as('minutes'); // v8 ignore else -- TODO: add test #40625 if (ttlMinutes && ttlMinutes > 0) { await packageCache.set( this.cacheNs, this.cacheKey, cacheRecord, ttlMinutes, ); } } }