Cache stars

This commit is contained in:
2024-09-28 01:28:50 +03:00
parent 041262d09b
commit 7f03065936
5 changed files with 32 additions and 40 deletions

View File

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