()
| 5 | |
| 6 | let _cacheManager: Keyv; |
| 7 | export async function getCacheManager() { |
| 8 | if (_cacheManager) { |
| 9 | return _cacheManager; |
| 10 | } |
| 11 | |
| 12 | let store: KeyvStoreAdapter | undefined = undefined; |
| 13 | if (!env.cache.memoryOnly) { |
| 14 | store = env.cache.redisUrl |
| 15 | ? new KeyvRedis({ |
| 16 | url: env.cache.redisUrl, |
| 17 | }) |
| 18 | : new KeyvPostgres({ |
| 19 | uri: env.db.url, |
| 20 | schema: 'cache', |
| 21 | table: 'cache', |
| 22 | }); |
| 23 | } |
| 24 | |
| 25 | const cacheManager = new Keyv({ |
| 26 | store: store ?? new Map(), |
| 27 | ttl: 10 * 60 * 1000, |
| 28 | namespace: 'tianji-cache', |
| 29 | }); |
| 30 | |
| 31 | _cacheManager = cacheManager; |
| 32 | |
| 33 | return cacheManager; |
| 34 | } |
| 35 | |
| 36 | interface BuildQueryWithCacheOptions { |
| 37 | /** |
no outgoing calls
no test coverage detected