© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•2y ago•
1 reply
Hugo

Cache « in-server » requests

Hey folks!

I have a SvelteKit app deployed through Pages (so my server endpoints are counted as Workers from a CF perspective).

In my page server load function (
+page.server.ts
+page.server.ts
) I have this:

// +page.server.ts

async function fetchRecentStuff(event: ServerLoadEvent){
    const url = '/api/stuff/recents'; // Also tried with absolute url: https://example.com/api/stuff/recents
    const response = await event.fetch(url);
    const recentStuff = await response.json();
    return recentStuff;
}

export const load: PageServerLoad = async (event) => {
    const stuff = await getStuff(event);
        return { stuff }
};
// +page.server.ts

async function fetchRecentStuff(event: ServerLoadEvent){
    const url = '/api/stuff/recents'; // Also tried with absolute url: https://example.com/api/stuff/recents
    const response = await event.fetch(url);
    const recentStuff = await response.json();
    return recentStuff;
}

export const load: PageServerLoad = async (event) => {
    const stuff = await getStuff(event);
        return { stuff }
};


And in the called endpoint:

// /routes/api/stuff/recents/+server.ts

async function getRecentStuff() {...}
async function getUserProfile(event) {...}

export const GET: RequestHandler = async (event) => {
    const mongoUser = await app.logIn(credentials);
    const mongoClient = mongoUser.mongoClient('mongodb');

    const userProfile = await getUserProfile(event)
    const recentStuff = await getRecentStuff(mongoClient, userProfile);

    return json(recentStuff);
};
// /routes/api/stuff/recents/+server.ts

async function getRecentStuff() {...}
async function getUserProfile(event) {...}

export const GET: RequestHandler = async (event) => {
    const mongoUser = await app.logIn(credentials);
    const mongoClient = mongoUser.mongoClient('mongodb');

    const userProfile = await getUserProfile(event)
    const recentStuff = await getRecentStuff(mongoClient, userProfile);

    return json(recentStuff);
};


My goal is to cache that request to /api/stuff/recents at the edge level, so I setup the attached rule.

My problem is it actually doesn't cache the request response. Maybe you have an hint? 🙂
CleanShot_2024-09-03_at_19.50.462x.png
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Cache server-to-server requests (SvelteKit)
Cloudflare DevelopersCDCloudflare Developers / general-help
2y ago
Tiered Cache and Range Requests
Cloudflare DevelopersCDCloudflare Developers / general-help
7mo ago
Cache Everything in Cache Rules (Images)
Cloudflare DevelopersCDCloudflare Developers / general-help
2y ago
Cache Everything in Cache Rules (Images)
Cloudflare DevelopersCDCloudflare Developers / general-help
2y ago