diff --git a/src/utils/bridgeVolume.ts b/src/utils/bridgeVolume.ts index dd4a3bcf..eebc4ea5 100644 --- a/src/utils/bridgeVolume.ts +++ b/src/utils/bridgeVolume.ts @@ -6,6 +6,7 @@ import { getConfigsWithDestChain, } from "./wrappa/postgres/query"; import { importBridgeNetwork } from "../data/importBridgeNetwork"; +import { cache } from "./cache"; const startTimestampToRestrictTo = 1661990400; // Sept. 01, 2022: timestamp data is backfilled to @@ -124,6 +125,11 @@ export const getHourlyBridgeVolume = async ( bridgeNetworkId?: number ) => { let bridgeDbName = undefined as any; + const cacheKey = `hourly_bridge_volume_${bridgeNetworkId}_${chain}_${startTimestamp}_${endTimestamp}`; + const cachedData = await cache.get(cacheKey); + if (cachedData) { + return cachedData as any[]; + } if (bridgeNetworkId) { const bridgeNetwork = importBridgeNetwork(undefined, bridgeNetworkId); if (!bridgeNetwork) { @@ -219,6 +225,7 @@ export const getHourlyBridgeVolume = async ( } } */ + await cache.set(cacheKey, hourlyBridgeVolume); return hourlyBridgeVolume; }; diff --git a/src/utils/cache.ts b/src/utils/cache.ts index 4b2f6093..42b148ec 100644 --- a/src/utils/cache.ts +++ b/src/utils/cache.ts @@ -1,14 +1,9 @@ import { LRUCache } from "lru-cache"; import hash from "object-hash"; -const MAX_SIZE_BYTES = 50 * 1024 * 1024; - export const cache = new LRUCache({ - maxSize: MAX_SIZE_BYTES, - sizeCalculation: (value: any) => { - return Buffer.byteLength(JSON.stringify(value), "utf8"); - }, - ttl: 100 * 60 * 12, + max: 1000, + ttl: 1000 * 60 * 60, }); interface APIEvent {