'cache: no store' not working in Production - App router
Answered
Russian Blue posted this in #help-forum
Original message was deleted.
39 Replies
Original message was deleted
because the route itself is static
try add
export const dynamic = "force-dynamic"Answer
Original message was deleted
yep
Russian Blue
@Ray thank you - so based on the docs, if I changed to .ts and used the below that should also work?
export async function GET(request: Request) {
const token = process.env.API_WEATHER_TOKEN; // Your API token
const url = `https://api.apify.com/v2/acts/shanes~tweet-flash/runs/last/dataset/items?token=${token}`;
try {
const response = await fetch(url, { cache: 'no-store' });
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return NextResponse.json(data, { status: 200 });
} catch (error) {
return NextResponse.json({ error: error.message }, { status: 500 });
}
}oh wait, are you using app router or page router?
Russian Blue
App Router
because i saw the path is
// pages/api/get_weather.jsRussian Blue
sorry that comment is wrong, it's app router
Russian Blue
Just to confirm, both options should work on App router?
export const dynamic = "force-dynamic" this only work in app routerI think the api route in page router is dynamic by default
Russian Blue
got it, thanks again
does it fix your issue?
Russian Blue
I believe so, but i wont know for sure until tomorrow morning when data updates and cron job runs
ah ok
Russian Blue
@Ray im not really understanding what
cache: no store does vs the force dynamic, any chance you can share more?cache: no store only cache the fetch resultbut the problem is your route is static generated
Russian Blue
ok gotcha, ill have to dig more into it
there is a report after you run
next buildyou should see that route is static generated
Russian Blue
is the report in the console or where?
in the console
it will print after the build finish
Russian Blue
ahh the symbol
thanks
yea
from the report, you have two api is static too
Russian Blue
so /cron I want to always update
that says sever so should be good
ill check the others
thanks again
Russian Blue
@Ray this worked, big thanks!
@Russian Blue <@743561772069421169> this worked, big thanks!
cool, please mark solution.
Russian Blue
How do I do that? First time using this
right click my answer > application > mark solution