Caching behavior for the same server function called in middleware and in another server function #64134
Unanswered
haidarkarrar
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to achieve caching on menu items
here the fetch inside menu is using the AppToken for Authorization, this is the getAppAuthToken function
I am caching the AppToken too to be able to achieve caching on menus since it is being used there, which is working perfectly,
my problem is authentication => logging in requires AppToken too same as menus,
which is forcing me to uncache the AppToken and add cache : 'no-store' for the fetch in getAuthAppToken() and this leads to losing the caching on menus which is understandable I guess.
BUUUUT what's weird is this, when getAppAuthToken is still cached ('force-cache') and I call a function that calls it from the Middleware it revalidate ONLYY on this function??
the middleware:
here the Middleware is awaiting refreshToken (which uses AppToken for Authorization),
the value of AppToken is always new which means it is being revalidated inside refreshToken()
but at the same time the value of the AppToken inside getMenu() is still the first cached value??? (the token is un-valid but getMenu() is not throwing 401 cause it is not being revalidated since AppToken is cached)
Is this the normal behavior? and if so, how can I achieve the same behavior between login() and getMenu same way between refreshToken() and getMenu() (to only revalidate AppToken inside the login() and keep the getMenu() cached)
Beta Was this translation helpful? Give feedback.
All reactions