You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's my attempt to provide stale-while-revalidate within Hono middleware that's drop-in compatible with the existing (lovely!) cache middleware.
Unfortunately, I cannot figure out if it's possible to serve a cached response while also revalidating next within middleware. As far as I can tell, this is not possible with the existing design, but I could be missing something?
My repository has a full test suite for my progress thus far. There is 1 failing test that describes the behaviour that I'm struggling to achieve. I've also updated the README with more information on the project in general.
My general belief is that if next accepts Context, I should be able to achieve what I'm seeking? Then I can essentially compose a new Context, pass that into next, and then operate on that Context within my middleware function. Something like:
constrevalidatingContext=newHonoRequestContext(existingRequestContext)// this parameter can be optional,// and defaulting to the `existingRequestContext` if not providedawaitnext(revalidatingContext)revalidatingContext.res// this is the mutated Response that I can work with
However I'm hesitant to explore such a solution if there are other ways of achieving what I'm looking for or other plans in place that would unlock this for me!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey there,
I created this repo: https://github.com/guild-host/hono-swr-cache
It's my attempt to provide
stale-while-revalidate
within Hono middleware that's drop-in compatible with the existing (lovely!)cache
middleware.Unfortunately, I cannot figure out if it's possible to serve a cached response while also revalidating
next
within middleware. As far as I can tell, this is not possible with the existing design, but I could be missing something?My repository has a full test suite for my progress thus far. There is 1 failing test that describes the behaviour that I'm struggling to achieve. I've also updated the README with more information on the project in general.
My general belief is that if
next
acceptsContext
, I should be able to achieve what I'm seeking? Then I can essentially compose a newContext
, pass that intonext
, and then operate on thatContext
within my middleware function. Something like:However I'm hesitant to explore such a solution if there are other ways of achieving what I'm looking for or other plans in place that would unlock this for me!
Let me know if there's a path forward here 🙏
Thank you for the awesome library! ❤️
Beta Was this translation helpful? Give feedback.
All reactions