Cache tweaks

This commit is contained in:
2024-09-28 01:29:28 +03:00
parent 7f03065936
commit a3b207afd8

View File

@@ -1,14 +1,15 @@
import type {PageServerLoad} from "./$types";
import getStars from "$lib/getStars";
const CACHE_LIFE = 1000 * 60 * 5
let lastRequest = Date.now()
let starCount: number
let starCount: number | null = null
export const load: PageServerLoad = async () => {
const now = Date.now()
const CACHE_LIFE = 1000 * 60 * 5
if (now - CACHE_LIFE > lastRequest || starCount === undefined) {
if (now - CACHE_LIFE > lastRequest || starCount === null) {
lastRequest = Date.now()
try {
starCount = await getStars('anatolykopyl')