fix: убрал у кеша ttl, добавил удаление кеша при создании новой записи

This commit is contained in:
Dhaverd 2026-07-22 13:58:09 +08:00
parent 9aeea7f22c
commit 4f054bc555

View File

@ -32,7 +32,7 @@ export class BlacklistService {
} }
const allRecords = await this.blacklistReportModel.findAll({ raw: true }); const allRecords = await this.blacklistReportModel.findAll({ raw: true });
if (allRecords.length > 0) { if (allRecords.length > 0) {
await this.cacheManager.set(cacheKey, allRecords, 60 * 1000); await this.cacheManager.set(cacheKey, allRecords);
const check = await this.cacheManager.get(cacheKey); const check = await this.cacheManager.get(cacheKey);
console.log('Данные в кэше:', check); console.log('Данные в кэше:', check);
} }
@ -67,7 +67,7 @@ export class BlacklistService {
where: { steam_link: link }, where: { steam_link: link },
}); });
if (allRecords.length > 0) { if (allRecords.length > 0) {
await this.cacheManager.set(cacheKey, allRecords, 60 * 1000); await this.cacheManager.set(cacheKey, allRecords);
const check = await this.cacheManager.get(cacheKey); const check = await this.cacheManager.get(cacheKey);
console.log('Данные в кэше:', check); console.log('Данные в кэше:', check);
} }
@ -150,6 +150,8 @@ export class BlacklistService {
async createBlacklistRecord( async createBlacklistRecord(
blackListReportDto: BlacklistReportDto, blackListReportDto: BlacklistReportDto,
): Promise<BlacklistReport> { ): Promise<BlacklistReport> {
const cacheKey = 'hunt-blacklist:all';
await this.cacheManager.del(cacheKey);
const report = BlacklistReport.build(blackListReportDto); const report = BlacklistReport.build(blackListReportDto);
return await report.save(); return await report.save();
} }