I fetch from CMS but if it is offline I don't want to throw error...
Answered
Rhinelander posted this in #help-forum
RhinelanderOP
I fetch from CMS get the data... All good but what if my CMS is offline I would like to cache latest data that my app got from there. If is set revalidate to something like 900 it will keep that just from 15 minutes and after that show error screen. Since this is a blog and new things gets added all the time data needs to be fresh. What should I do
Answered by B33fb0n3
Then you might want to cache the page for an infinite amount of time. When the cms is offline, there shouldn't be updates to the content. So that's fine. If the cms is online again and something changes, you can revalidate the page and the page instantly gets the new details
8 Replies
@Rhinelander I fetch from CMS get the data... All good but what if my CMS is offline I would like to cache latest data that my app got from there. If is set revalidate to something like 900 it will keep that just from 15 minutes and after that show error screen. Since this is a blog and new things gets added all the time data needs to be fresh. What should I do
If I understood your problem right, you can cache the whole page with
export const revalidate = 900 // 15 min in seconds until next revalidation. Then throw an error when the cms is offlineRhinelanderOP
I dont want user to see that cms is offline. Solution above is already implemented. Sure message in the logs but i dont want user to know that, i just want them to use app like there is no problem
@Rhinelander I dont want user to see that cms is offline. Solution above is already implemented. Sure message in the logs but i dont want user to know that, i just want them to use app like there is no problem
... and after that show error screenbut that does not sound like that your user shouldn't know that there is an error 🤔
Can you clarify that please?
RhinelanderOP
Well i want user to access the cached blog all the time. Not to throw error if there is problem with my cms. If there is problem with cms i will try to fix that but i dont want user to see that there is problem
@Rhinelander Well i want user to access the cached blog all the time. Not to throw error if there is problem with my cms. If there is problem with cms i will try to fix that but i dont want user to see that there is problem
Then you might want to cache the page for an infinite amount of time. When the cms is offline, there shouldn't be updates to the content. So that's fine. If the cms is online again and something changes, you can revalidate the page and the page instantly gets the new details
Answer
@B33fb0n3 Then you might want to cache the page for an infinite amount of time. When the cms is offline, there shouldn't be updates to the content. So that's fine. If the cms is online again and something changes, you can revalidate the page and the page instantly gets the new details
For the revalidation part, you can create a route called by your CMS on update. In that route, you can call
doc: https://nextjs.org/docs/app/api-reference/functions/revalidatePath
or revalidate tag if you cache the content and not the page:
https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation
revalidatePath(<path-to-update>)doc: https://nextjs.org/docs/app/api-reference/functions/revalidatePath
or revalidate tag if you cache the content and not the page:
https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation
RhinelanderOP
Thanks
Happy to help