diff --git a/sitio/src/routes/+page.server.ts b/sitio/src/routes/+page.server.ts index 2f44867..0fd646d 100644 --- a/sitio/src/routes/+page.server.ts +++ b/sitio/src/routes/+page.server.ts @@ -1,9 +1,14 @@ -import type { PageServerLoad } from "./$types"; +import type { PageData, PageServerLoad } from "./$types"; import { db, schema } from "$lib/server/db"; const { precios } = schema; import { sql } from "drizzle-orm"; +let cache: null | { key: Date; data: PageData } = null; + export const load: PageServerLoad = async ({ params }) => { + if (cache && +new Date() < +cache.key + 1000 * 60 * 10) { + return cache.data; + } const q = db .select({ ean: precios.ean, @@ -16,5 +21,7 @@ export const load: PageServerLoad = async ({ params }) => { .orderBy(sql`random()`) .limit(150); const res = await q; - return { precios: res }; + const data = { precios: res }; + cache = { key: new Date(), data }; + return data; };