feat: customer detail page, size snapshots table, Spaces provisioning, Redis status cache
Some checks failed
Build & Release / build (push) Has been cancelled
Some checks failed
Build & Release / build (push) Has been cancelled
This commit is contained in:
33
src/lib/cache.ts
Normal file
33
src/lib/cache.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import Redis from "ioredis";
|
||||
import { config } from "./config";
|
||||
|
||||
// Manager uses the managed Valkey with "mgr:" prefix so it doesn't collide with customer keys
|
||||
export const cache = new Redis(config.managedValkeyUrl, {
|
||||
keyPrefix: "mgr:",
|
||||
lazyConnect: true,
|
||||
enableReadyCheck: false,
|
||||
});
|
||||
|
||||
const STATUS_TTL = 120; // seconds
|
||||
|
||||
export async function getCachedStatus(slug: string): Promise<{ data: any; cachedAt: string } | null> {
|
||||
try {
|
||||
const raw = await cache.get(`status:${slug}`);
|
||||
if (!raw) return null;
|
||||
return JSON.parse(raw);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function setCachedStatus(slug: string, data: any): Promise<void> {
|
||||
try {
|
||||
await cache.set(`status:${slug}`, JSON.stringify({ data, cachedAt: new Date().toISOString() }), "EX", STATUS_TTL);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
export async function invalidateCachedStatus(slug: string): Promise<void> {
|
||||
try {
|
||||
await cache.del(`status:${slug}`);
|
||||
} catch {}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ export const config = {
|
||||
doadminDbUrl: process.env.DOADMIN_DATABASE_URL!,
|
||||
jwtSecret: process.env.JWT_SECRET!,
|
||||
managedValkeyUrl: process.env.MANAGED_VALKEY_URL!,
|
||||
spacesBucket: process.env.SPACES_BUCKET ?? "lunarfront-data",
|
||||
spacesRegion: process.env.SPACES_REGION ?? "nyc3",
|
||||
};
|
||||
|
||||
for (const [key, val] of Object.entries(config)) {
|
||||
|
||||
@@ -10,7 +10,7 @@ function token() {
|
||||
return readFileSync(SA_TOKEN_PATH, "utf-8").trim();
|
||||
}
|
||||
|
||||
async function k8sFetch(path: string, options: RequestInit = {}, allowStatuses: number[] = []) {
|
||||
export async function k8sFetch(path: string, options: RequestInit = {}, allowStatuses: number[] = []) {
|
||||
const res = await fetch(`${K8S_API}${path}`, {
|
||||
...options,
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user