-
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.
Signed-off-by: sarthakjdev <jsarthak448@gmail.com>
- Loading branch information
1 parent
e914c25
commit a42d511
Showing
3 changed files
with
88 additions
and
90 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,27 +1,27 @@ | ||
import { caching } from 'cache-manager' | ||
|
||
const cacheStore = caching({ | ||
store: 'memory' | ||
store: 'memory' | ||
}) | ||
|
||
export async function cacheData(params: { key: string; data: any; ttl?: number }) { | ||
const { key, ttl, data } = params | ||
await cacheStore.set(key, data, { ...(ttl ? { ttl: ttl } : {}) }) | ||
const { key, ttl, data } = params | ||
await cacheStore.set(key, data, { ...(ttl ? { ttl: ttl } : {}) }) | ||
} | ||
|
||
export async function getCachedData<T>(key: string): Promise<T> { | ||
const response = await cacheStore.get(key) | ||
console.log(response) | ||
return response as T | ||
const response = await cacheStore.get(key) | ||
console.log(response) | ||
return response as T | ||
} | ||
|
||
export function computeCacheKey(params: { id: string; context: string }) { | ||
return `${params.id}-${params.context}` | ||
return `${params.id}-${params.context}` | ||
} | ||
|
||
export function getConversationContextCacheKey(phoneNumber: string) { | ||
return computeCacheKey({ | ||
id: phoneNumber, | ||
context: 'conversation' | ||
}) | ||
return computeCacheKey({ | ||
id: phoneNumber, | ||
context: 'conversation' | ||
}) | ||
} |
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