Using Route Segment Config for React `cache()`
Unanswered
Highlander posted this in #help-forum
HighlanderOP
Hey everyone, in this example: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#example, it says that we can use the route segment config to configure the caching behavior of the
If it tied to the function, what's the difference between the
cache() function which originally only act as a memoization tool for deduping same requests per-call. The example shows that the configuration (export const revalidate = ...) is declared within the utils/get-item.ts function, which I assume it's a separate file dedicated for helper, not tied to a single route, and it can be imported from a different routes. Does that means the configuration only applied to get-item.ts or it'll affect the route that importing the function?If it tied to the function, what's the difference between the
unstable_cache?36 Replies
cache() and const revalidate are kinda diferent... cache() is only for the same render/request while revalidate is for the whole page bing cached... unstable_cache is the same fetch cache APIs where it can be cached cross requestsand
export const revalidate is for the whole page, so putting it not in page/layout would not be used...wait the example says it does...? (im going to assume it is saying you cant)
it would, they will pick the lowest revalidate number
hmm i havent tried using it in that case
interesting
i can't tell what would happen ngl
that needs to be clarified
how would that even work :/
yeah i think they are trying to say it won't but i am really not sure
I think it works by setting the cache of the exported function
but like is that a thing? as as OP said, what is unstable cache for then?
bonkers xD
is it somehow messing with the actual revalidate config as you mentioned ealier?
@aardani it would, they will pick the lowest revalidate number
HighlanderOP
If that's case, the next.js builder would look into every file imported by the page and layout to find the revalidate const 🤔
i just tried, and my basic test has only the dedupe and no other caching
@Highlander If that's case, the next.js builder would look into every file imported by the page and layout to find the revalidate const 🤔
i couldn't get it to do this... either they changed how things work... or idk
@riský i just tried, and my basic test has only the dedupe and no other caching
HighlanderOP
same as my understanding, thanks a lot for testing.
but i remember then saying how this isn't a thing... so why are they wording it so badly
mwaha
but idk what the intended method is...
it could be a bug that it isn't working
you can always make the issue first iirc
ask joulev xd i always forget the step
ask joulev xd i always forget the step
i should try in canary... but not bothered enough rn ;(
@riský but i remember then saying how this isn't a thing... so why are they wording it so badly
HighlanderOP
I think they're trying to say that "You can use the route config together with the
cache", but the writer forgot to separate the file for the codeyeah that is what i hope
but imo unless it is really clear, they shouldn't add codeblocks with invalid code
@aardani does't seem like it is the first time you got confused about this: https://github.com/vercel/next.js/issues/5454
sorry what?
wait wrong
@aardani sorry what?
lol sorry i meant: https://github.com/vercel/next.js/issues/54547 (but somehow github copied the wrong one??? i haven't seen that one i somehow linked)