jakala-na / next-contentful-starterkit

https://next-contentful-starterkit.vercel.app/
MIT License
2 stars 0 forks source link

Adopt Caching and on-demand revalidation strategies #16

Open asgorobets opened 9 months ago

asgorobets commented 9 months ago

This is likely less of a priority if we have mostly static content, and ISR (5 minutes for examples) are pretty effective ways to achieve revalidation, but there are cases when we do need to evict cache for something long term. Especially in App Router scenarios.

A few scenarios:

On demand revalidation requires ability to set "next" property on Fetch, or wrap a response in https://nextjs.org/docs/app/api-reference/functions/unstable_cache. For this reason, we're dependent on the decision in #13. If it's a library with no support for fetch props, then it's unstable_cache.

Few considerations:

NextJS docs to reference: https://nextjs.org/docs/app/building-your-application/caching#fetch-optionsnexttags-and-revalidatetag

Contentful article for reference: https://www.contentful.com/blog/integrate-contentful-next-js-app-router/

asgorobets commented 7 months ago

Addition of tags to fetch requests is now possible with #35, but we should still explore granular cache tags and longer cache lifetimes with webhooks-style invalidation in this ticket. My inclination is that managing it with webhooks or even App Framework App Events is going to be very custom and not worth the effort for majority scenarios, but it will be good for certain one-off scenarios like menu or some specific feature tied to specific content types.

Also, there are 64 tags maximum as of writing that can be attached to a request: https://nextjs.org/docs/app/api-reference/functions/fetch#optionsnexttags

There are some discussions to explore here: https://www.reddit.com/r/nextjs/comments/16smmz6/optimizing_cache_invalidation_in_nextjs13_seeking/

asgorobets commented 4 weeks ago

Glad we waited, we'll have to use Next 15 for anything caching =)