import { persistedCache, revalidateTag } from "beth-stack/cache"; import { renderToStream, renderToString, Suspense } from "beth-stack/jsx"; import { Elysia } from "elysia"; import { BaseHtml } from "../components/base"; import { ctx } from "../context"; const start = Date.now(); const getTime = async () => (Date.now() - start) / 1000; const cachedGetTime = persistedCache(getTime, "getTime", { tags: ["time"], revalidate: 2, }); export const index = new Elysia() .use(ctx) .onRequest(({ request }) => { const revalidate = request.headers.get("HX-Revalidate"); if (revalidate) { const tags = JSON.parse(revalidate); if (!Array.isArray(tags)) { return; } tags.forEach((tag) => { if (typeof tag !== "string") { return; } revalidateTag(tag); }); } }) .get("/test", async ({ html, log }) => { log.info("test"); const time = await cachedGetTime(); return html(() =>

{time}

); }) .get("/", async ({ html }) => { return html(() => (

cache revalidates every two seconds


hot reload

)); }) .get("/test2", async ({ htmlStream }) => { return htmlStream(() => ); }); function wait(ms: number): Promise { return new Promise((resolve) => setTimeout(() => { resolve(ms); }, ms), ); } export async function Wait({ ms }: { ms: number }) { const data = await wait(ms); return
loaded in: {data}ms
; } const App2 = () => (

I am sent immediately

Loading...
}>
hello

hey me too!

loading 2...}>
hello two!
loading 3...}>
hello three!
);