diff --git a/packages/backend/src/core/SponsorsService.ts b/packages/backend/src/core/SponsorsService.ts index 3769378f5a..b83c109985 100644 --- a/packages/backend/src/core/SponsorsService.ts +++ b/packages/backend/src/core/SponsorsService.ts @@ -3,12 +3,11 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import { Inject, Injectable, OnApplicationShutdown } from '@nestjs/common'; -import * as Redis from 'ioredis'; +import { Inject, Injectable } from '@nestjs/common'; import type { MiMeta } from '@/models/_.js'; import { DI } from '@/di-symbols.js'; -import { RedisKVCache } from '@/misc/cache.js'; import { bindThis } from '@/decorators.js'; +import { CacheManagementService, type ManagedRedisKVCache } from '@/core/CacheManagementService.js'; export interface Sponsor { MemberId: number; @@ -34,17 +33,16 @@ export interface Sponsor { } @Injectable() -export class SponsorsService implements OnApplicationShutdown { - private readonly cache: RedisKVCache; +export class SponsorsService { + private readonly cache: ManagedRedisKVCache; constructor( @Inject(DI.meta) private readonly meta: MiMeta, - @Inject(DI.redis) - redisClient: Redis.Redis, + cacheManagementService: CacheManagementService, ) { - this.cache = new RedisKVCache(redisClient, 'sponsors', { + this.cache = cacheManagementService.createRedisKVCache('sponsors', { lifetime: 1000 * 60 * 60, memoryCacheLifetime: 1000 * 60, fetcher: (key) => { @@ -102,9 +100,4 @@ export class SponsorsService implements OnApplicationShutdown { if (forceUpdate) await this.cache.refresh('sharkey'); return this.cache.fetch('sharkey'); } - - @bindThis - public onApplicationShutdown(): void { - this.cache.dispose(); - } }