You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Has anyone had luck caching trpc responses when making fetch calls from edge function to a serverless function (deployment on vercel). I never seem to be able to get the cache working in such setup. I'm using QwikJS
Example code snipped in the edge function:
consthandler: RequestHandler=async({
request,
json,
sharedMap,
redirect
})=>{constsession: Session=sharedMap.get("session");if(!session?.user?.id)redirect(307,"/landing");constresponse=awaitfetchRequestHandler({// the endpoint handling the requestsendpoint: "/api/trpc",// the request objectreq: request,// the router for handling the requestsrouter: appRouter,// any arbitary data that should be available to all actionscreateContext: ()=>({}),responseMeta(opts){const{ errors }=opts;// checking that no procedures erroredconstallOk=errors.length===0;if(allOk){// cache request for 1 day + revalidate once every secondconstONE_DAY_IN_SECONDS=60*60*24;return{headers: {"cache-control": `s-maxage=60, stale-while-revalidate=${ONE_DAY_IN_SECONDS}`,},};}return{};},}constdata=awaitresponse.json();json(200,data);};exportconstonGet=handler;exportconstonPost=handler;
when checking the vercel logs I'm aways gettint a cache MISS and I never see the cached value being returned.
Inspecting the response headers that get to edge function recieves, it looks that the cache-control is getting stripped and replaced with different value (public, max-age=0, must-revalidate)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Has anyone had luck caching trpc responses when making fetch calls from edge function to a serverless function (deployment on vercel). I never seem to be able to get the cache working in such setup.
I'm using QwikJS
Example code snipped in the edge function:
when checking the vercel logs I'm aways gettint a cache MISS and I never see the cached value being returned.
Inspecting the response headers that get to edge function recieves, it looks that the cache-control is getting stripped and replaced with different value
(public, max-age=0, must-revalidate)
Beta Was this translation helpful? Give feedback.
All reactions