(key: string)
| 25 | } |
| 26 | |
| 27 | export async function getCache<T>(key: string): Promise<T | null> { |
| 28 | if (!Settings.CACHE_ENABLED) { |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | try { |
| 33 | const cacheEntry = await prisma.cache.findUnique({ |
| 34 | where: { key }, |
| 35 | }); |
| 36 | |
| 37 | if (!cacheEntry) { |
| 38 | return null; |
| 39 | } |
| 40 | |
| 41 | if (cacheEntry.expiresAt < new Date()) { |
| 42 | await prisma.cache.delete({ |
| 43 | where: { key }, |
| 44 | }); |
| 45 | return null; |
| 46 | } |
| 47 | |
| 48 | return JSON.parse(cacheEntry.value) as T; |
| 49 | } catch (error) { |
| 50 | console.error(`Failed to get cache for key ${key}:`, error); |
| 51 | return null; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | export async function setCache<T>( |
| 56 | key: string, |
no outgoing calls
no test coverage detected