frontend/src/routes/blog/+page.ts
2024-10-07 16:15:17 +02:00

31 lines
800 B
TypeScript

import { pb } from "$lib/pocketbase";
import { getCache, setCache } from "$lib/store";
export const load = async () => {
const getAllBlogPost = async () => {
let output;
// Get cached data for the specific tickerID
const cachedData = getCache("allBlogPost", "getAllBlogPost");
if (cachedData) {
output = cachedData;
} else {
// make the POST request to the endpoint
output = await pb.collection("articles").getFullList({
expand: "user",
sort: "-created",
});
// Cache the data for this specific tickerID with a specific name 'getAllBlogPost'
setCache("allBlogPost", output, "getAllBlogPost");
}
return output;
};
// Make sure to return a promise
return {
getAllBlogPost: await getAllBlogPost(),
};
};