feat: move some stuff around

This commit is contained in:
2023-08-01 18:35:35 +02:00
parent c5cf629482
commit e51667bbac
9 changed files with 97 additions and 63 deletions

21
lib/cache/cache.ts vendored
View File

@ -19,7 +19,7 @@ async function createCache<T>(): Promise<Map<string, T> | Redis> {
conf.password = REDIS_PASS;
}
const client = await connect(conf);
console.log("Connected to redis");
console.log("[redis] connected");
return client;
}
@ -33,15 +33,26 @@ export async function get<T>(id: string, binary = false) {
const cacheHit = await cache.sendCommand("GET", [id], {
returnUint8Arrays: true,
}) as T;
if (cacheHit) console.log("[cache] HIT ", { id });
else console.log("[cache] MISS", { id });
return cacheHit;
}
const cacheHit = await cache.get(id) as T;
if (cacheHit) console.log("[cache] HIT ", { id });
else console.log("[cache] MISS", { id });
return cacheHit;
}
export function clearAll() {
if ("flushall" in cache) {
return cache.flushall();
} else {
for (const k of cache.keys()) {
cache.delete(k);
}
}
}
export function expire(id: string, seconds: number) {
if ("expire" in cache) {
return cache.expire(id, seconds);
}
}
export async function set<T extends RedisValue>(id: string, content: T) {
console.log("[cache] storing ", { id });

2
lib/cache/image.ts vendored
View File

@ -49,6 +49,8 @@ export async function setImage(
const pointerId = await hash(cacheKey);
await cache.set(pointerId, clone);
cache.expire(pointerId, 60 * 10);
cache.expire(cacheKey, 60 * 10);
await cache.set(
cacheKey,

View File

@ -1,5 +1,5 @@
import { unified } from "https://esm.sh/unified";
import remarkParse from "https://esm.sh/remark-parse";
import { unified } from "https://esm.sh/unified@10.1.2";
import remarkParse from "https://esm.sh/remark-parse@10.0.2";
import remarkStringify from "https://esm.sh/remark-stringify@10.0.3";
import remarkFrontmatter, {
Root,