-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ab4d40
commit e62a1e4
Showing
4 changed files
with
68 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
|
||
*.html | ||
# Logs | ||
logs | ||
*.log | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable prettier/prettier */ | ||
import { RedisService } from 'src/cache/redis/redis.service'; | ||
|
||
export class CacheManager { | ||
|
||
static async set(key: string, data: any) { | ||
try { | ||
const cache = RedisService.client; | ||
let prevData = await CacheManager.get(key); | ||
prevData = prevData ? prevData : {}; | ||
const newData = { ...prevData, ...data }; | ||
return await cache.set(key.toString(), JSON.stringify(newData)); | ||
} catch (error) { | ||
console.log("Error in setting to cache ", error?.message); | ||
return false; | ||
} | ||
} | ||
|
||
static async get(key: string) { | ||
try { | ||
const cache = RedisService.client; | ||
const response = await cache.get(key.toString()); | ||
return JSON.parse(response); | ||
} catch (error) { | ||
console.log("Error in getting from cache ", error?.message); | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters