Initial Commit with Working server and metrics

This commit is contained in:
2025-10-11 21:41:03 +02:00
commit 368383ba5c
16 changed files with 2839 additions and 0 deletions

36
dist/cache.js vendored Normal file
View File

@@ -0,0 +1,36 @@
import { LRUCache } from "lru-cache";
import config from "./config.js";
let redis = null;
let useRedis = false;
export async function initCache() {
if (config.redisUrl) {
const { createClient } = await import("redis");
redis = createClient({ url: config.redisUrl });
await redis.connect();
useRedis = true;
}
}
const lru = new LRUCache({ max: 1000 });
export async function get(key) {
if (useRedis) {
const raw = await redis.get(key);
return raw ? JSON.parse(raw) : null;
}
return lru.get(key) ?? null;
}
export async function set(key, val) {
if (useRedis) {
await redis.set(key, JSON.stringify(val));
}
else {
lru.set(key, val);
}
}
export async function del(key) {
if (useRedis) {
await redis.del(key);
}
else {
lru.delete(key);
}
}