swagger configurado na rota chavenfe
This commit is contained in:
15
src/shared/cache.util.ts
Normal file
15
src/shared/cache.util.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { IRedisClient } from '../core/configs/cache/IRedisClient';
|
||||
|
||||
export async function getOrSetCache<T>(
|
||||
redisClient: IRedisClient,
|
||||
key: string,
|
||||
ttlSeconds: number,
|
||||
fallback: () => Promise<T>
|
||||
): Promise<T> {
|
||||
const cached = await redisClient.get<T>(key);
|
||||
if (cached) return cached;
|
||||
|
||||
const data = await fallback();
|
||||
await redisClient.set<T>(key, data, ttlSeconds);
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user