fix/cache: reduce cachetime when null response from CS. Fix fuzzy delete * fix/cache: reduce cachetime when null response from CS. Fix fuzzy delete Approved-by: Anton Gunnarsson
44 lines
1.0 KiB
TypeScript
44 lines
1.0 KiB
TypeScript
import * as Sentry from "@sentry/nextjs"
|
|
|
|
import { cacheLogger } from "../logger"
|
|
import { API_KEY } from "./client"
|
|
import { getCacheEndpoint } from "./endpoints"
|
|
|
|
export async function deleteKey<T>(key: string, opts?: { fuzzy?: boolean }) {
|
|
const perf = performance.now()
|
|
const endpoint = getCacheEndpoint(key)
|
|
|
|
if (opts?.fuzzy) {
|
|
endpoint.searchParams.set("fuzzy", "true")
|
|
}
|
|
|
|
const response = await fetch(endpoint, {
|
|
method: "DELETE",
|
|
cache: "no-cache",
|
|
headers: {
|
|
"x-api-key": API_KEY,
|
|
},
|
|
})
|
|
|
|
if (!response.ok) {
|
|
if (response.status !== 404) {
|
|
Sentry.captureMessage("Unable to DELETE cachekey", {
|
|
level: "error",
|
|
extra: {
|
|
cacheKey: key,
|
|
statusCode: response?.status,
|
|
statusText: response?.statusText,
|
|
},
|
|
})
|
|
}
|
|
|
|
return undefined
|
|
}
|
|
|
|
const data = (await response.json()) as { data: T }
|
|
cacheLogger.debug(
|
|
`Delete '${key}' took ${(performance.now() - perf).toFixed(2)}ms`
|
|
)
|
|
return data.data
|
|
}
|