import * as Sentry from "@sentry/nextjs" import { safeTry } from "@/utils/safeTry" import { type CacheTime, getCacheTimeInSeconds } from "../Cache" import { API_KEY } from "./client" import { getCacheEndpoint } from "./endpoints" export async function set(key: string, value: T, ttl: CacheTime) { const [response, error] = await safeTry( fetch(getCacheEndpoint(key), { method: "PUT", headers: { "Content-Type": "application/json", "x-api-key": API_KEY, }, body: JSON.stringify({ data: value, ttl: getCacheTimeInSeconds(ttl) }), cache: "no-cache", }) ) if (!response || error || !response.ok) { Sentry.captureMessage("Unable to SET cachekey", { level: "error", extra: { cacheKey: key, errorMessage: error instanceof Error ? error.message : undefined, statusCode: response?.status, statusText: response?.statusText, }, }) } }