Cache stars
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user