feat: enable React Compiler, add Redis caching for API routes, update README with requirements and install guide
Local Build and Deploy / deploy (push) Failing after 57s

This commit is contained in:
openhands committed 2026-07-20 14:14:49 +02:00
1 parent f53d25e0a5
commit ccd4994028
5 files changed
+248 -267

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
import "server-only";
import { redis } from "@/lib/redis";
/**
* Cache the result of a fetch function in Redis.
* Falls back to the fresh fetch if Redis is unavailable.
*/
export async function redisCache<T>(
key: string,
ttlSeconds: number,
fetch: () => Promise<T>,
): Promise<T> {
if (!redis) return fetch();
try {
const cached = await redis.get(key);
if (cached !== null) {
return JSON.parse(cached) as T;
}
} catch {
// cache miss or error — fall through to fresh fetch
}
const fresh = await fetch();
try {
await redis.setex(key, ttlSeconds, JSON.stringify(fresh));
} catch {
// ignore write errors
}
return fresh;
}
/**
* Invalidate a cached key. No-op if Redis is unavailable.
*/
export async function invalidateCache(key: string): Promise<void> {
if (!redis) return;
try {
await redis.del(key);
} catch {
// ignore
}
}
/**
* Build a namespaced cache key for API routes.
*/
export function apiCacheKey(path: string): string {
return `api:${path}`;
}