Server actions & next/cache
Unanswered
West African Lion posted this in #help-forum
West African LionOP
Hello 👋
Mine is quite a simple problem, and i feel like i might be misunderstanding something 😢 Check out this
Now, my understanding is that the
- Is my understanding of cross-request cache incorrect?
- How would you implement this kind of endpoint if your goal was to send two requests and see one
Mine is quite a simple problem, and i feel like i might be misunderstanding something 😢 Check out this
route.tsx file in my app router application:import { unstable_cache } from "next/cache";
async function fetchSession() {
console.log("fetchSession executed");
return "foo";
}
const getSession = unstable_cache(fetchSession, ["session"]);
export async function GET(request: Request) {
const session = await getSession();
return Response.json({ session });
}Now, my understanding is that the
unstable_cache works between requests. However if i call this endpoint twice in a row i will see "fetchSession executed" logged twice in console.- Is my understanding of cross-request cache incorrect?
- How would you implement this kind of endpoint if your goal was to send two requests and see one
console.log1 Reply
West African LionOP
In server actions the behaviour is the same, thus the title