( cache: Keyv, key: string, )
| 182 | * Get a cached value along with its remaining TTL |
| 183 | */ |
| 184 | export async function getCacheValueWithTTL( |
| 185 | cache: Keyv, |
| 186 | key: string, |
| 187 | ): Promise<{ data: any; remainingTTL: number } | undefined> { |
| 188 | const value = await getCacheValue(cache, key); |
| 189 | |
| 190 | if (!value) return undefined; |
| 191 | |
| 192 | const expiryData = await getCacheValue(cache, `${key}__expires_at`); |
| 193 | const remainingTTL = expiryData?.exp ? Math.max(0, expiryData.exp - Date.now()) : 0; |
| 194 | |
| 195 | return { data: value, remainingTTL }; |
| 196 | } |
| 197 | |
| 198 | function getKeyvInstance(store: Store, ttl: number | undefined, namespaceSuffix?: string): Keyv { |
| 199 | switch (store) { |
no test coverage detected