From a19343d3e1a439aed50405792445399f03038573 Mon Sep 17 00:00:00 2001 From: Judson Cairo Date: Wed, 28 Aug 2024 09:59:40 -0300 Subject: [PATCH] Validate if cache exists before accessing it --- src/api/services/cache.service.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/api/services/cache.service.ts b/src/api/services/cache.service.ts index 1004bb9c..af337ac9 100644 --- a/src/api/services/cache.service.ts +++ b/src/api/services/cache.service.ts @@ -21,6 +21,9 @@ export class CacheService { } public async hGet(key: string, field: string) { + if (!this.cache) { + return null; + } try { const data = await this.cache.hGet(key, field); @@ -43,6 +46,9 @@ export class CacheService { } public async hSet(key: string, field: string, value: any) { + if (!this.cache) { + return; + } try { const json = JSON.stringify(value, BufferJSON.replacer); @@ -67,6 +73,9 @@ export class CacheService { } async hDelete(key: string, field: string) { + if (!this.cache) { + return false; + } try { await this.cache.hDelete(key, field); return true;