Fix/SW-2401 share cache in prod * fix: reuse cache between prod and pre-prod * tests: add tests for generating cachePrefix * tests: remove unnecessary reset of process.env * tests: add tests for generateCacheKey * fix: make sure that we don't get invalid cacheKeys * fix: make sure that we don't get invalid cacheKeys Approved-by: Linus Flood
23 lines
498 B
TypeScript
23 lines
498 B
TypeScript
import { env } from "@/env/server"
|
|
|
|
export function getCacheEndpoint(key: string) {
|
|
if (!env.REDIS_API_HOST) {
|
|
throw new Error("REDIS_API_HOST is not set")
|
|
}
|
|
|
|
const url = new URL(`/api/cache`, env.REDIS_API_HOST)
|
|
url.searchParams.set("key", encodeURIComponent(key))
|
|
|
|
return url
|
|
}
|
|
|
|
export function getClearCacheEndpoint() {
|
|
if (!env.REDIS_API_HOST) {
|
|
throw new Error("REDIS_API_HOST is not set")
|
|
}
|
|
|
|
const url = new URL(`/api/cache/clear`, env.REDIS_API_HOST)
|
|
|
|
return url
|
|
}
|