diff --git a/api/_cache.ts b/api/_cache.ts index cb92e0e1c..b170042e3 100644 --- a/api/_cache.ts +++ b/api/_cache.ts @@ -1,8 +1,21 @@ import { kv } from "@vercel/kv"; import { interfaces } from "@across-protocol/sdk"; +const { + KV_REST_API_READ_ONLY_TOKEN, + KV_REST_API_TOKEN, + KV_REST_API_URL, + KV_URL, +} = process.env; +const isRedisCacheEnabled = + KV_REST_API_URL && KV_REST_API_TOKEN && KV_REST_API_READ_ONLY_TOKEN && KV_URL; + export class RedisCache implements interfaces.CachingMechanismInterface { async get(key: string): Promise { + if (!isRedisCacheEnabled) { + return null; + } + const value = await kv.get(key); if (value === null || value === undefined) { return null; @@ -11,6 +24,10 @@ export class RedisCache implements interfaces.CachingMechanismInterface { } async set(key: string, value: T, ttl = 10): Promise { + if (!isRedisCacheEnabled) { + return; + } + try { if (typeof value === "string") { try {