Skip to content

Commit

Permalink
Updated Cache.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
TanmayDhobale authored Mar 11, 2024
1 parent 463d834 commit 14569ce
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/db/Cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Cache {
return Cache.instance;
}

set(type: string, args: string[], value: any, expiryInSeconds: number = 3600): void {
set(type: string, args: string[], value: any, expiryInSeconds: number = parseInt(process.env.CACHE_EXPIRE_S || '100', 10)): void {
const currentTime = new Date().getTime();
const expiry = currentTime + expiryInSeconds * 1000;
this.inMemoryDb.set(`${type} ${JSON.stringify(args)}`, { value, expiry });
Expand All @@ -22,14 +22,12 @@ export class Cache {
get(type: string, args: string[]): any | null {
const key = `${type} ${JSON.stringify(args)}`;
const cacheEntry = this.inMemoryDb.get(key);
if (cacheEntry) {
if (cacheEntry.expiry > new Date().getTime()) {
if (cacheEntry && cacheEntry.expiry > new Date().getTime()) {
return cacheEntry.value;
} else {
} else {
this.inMemoryDb.delete(key);
}
return null;
}
return null;
}

evict(type: string, args: string[]): void {
Expand Down

0 comments on commit 14569ce

Please sign in to comment.