diff --git a/api/src/setting/seeds/setting.seed.ts b/api/src/setting/seeds/setting.seed.ts index 9da44a326..ea9e0d69f 100644 --- a/api/src/setting/seeds/setting.seed.ts +++ b/api/src/setting/seeds/setting.seed.ts @@ -6,8 +6,11 @@ * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). */ -import { Injectable } from '@nestjs/common'; +import { CACHE_MANAGER } from '@nestjs/cache-manager'; +import { Inject, Injectable } from '@nestjs/common'; +import { Cache } from 'cache-manager'; +import { SETTING_CACHE_KEY } from '@/utils/constants/cache'; import { BaseSchema } from '@/utils/generics/base-schema'; import { BaseSeeder } from '@/utils/generics/base-seeder'; @@ -16,7 +19,10 @@ import { Setting } from '../schemas/setting.schema'; @Injectable() export class SettingSeeder extends BaseSeeder { - constructor(private readonly settingRepository: SettingRepository) { + constructor( + private readonly settingRepository: SettingRepository, + @Inject(CACHE_MANAGER) private readonly cacheManager: Cache, + ) { super(settingRepository); } @@ -35,6 +41,9 @@ export class SettingSeeder extends BaseSeeder { if ((await this.repository.count({ group })) === 0) await this.repository.createMany(models); }); + + await this.cacheManager.del(SETTING_CACHE_KEY); + return true; } } diff --git a/api/src/setting/services/setting.service.ts b/api/src/setting/services/setting.service.ts index 7ac73bf66..022519c4f 100644 --- a/api/src/setting/services/setting.service.ts +++ b/api/src/setting/services/setting.service.ts @@ -105,13 +105,20 @@ export class SettingService extends BaseService { return config; } + /** + * Clears the settings cache + */ + async clearCache() { + this.cacheManager.del(SETTING_CACHE_KEY); + } + /** * Event handler for setting updates. Listens to 'hook:setting:*' events * and invalidates the cache for settings when triggered. */ @OnEvent('hook:setting:*') async handleSettingUpdateEvent() { - this.cacheManager.del(SETTING_CACHE_KEY); + this.clearCache(); } /**