I Was Surprised How Next.js Cached My Server Components

Поділитися
Вставка
  • Опубліковано 4 жов 2024

КОМЕНТАРІ • 12

  • @Aaronmoreno
    @Aaronmoreno 3 місяці тому +1

    So helpful. Thanks for breaking this down so simply

    • @JamesQQuick
      @JamesQQuick  3 місяці тому

      So glad you found it helpful!

  • @PraiseYeezus
    @PraiseYeezus 3 місяці тому +2

    Basically, if there's data that Next can't know ahead of time, like a dynamic route or query params/search params or a cookie or header, the page is dynamic. If the data you need is accessible at build time and not just request time, it will default to static. If you want to avoid static pages altogether and never deal with caching, use the 'force-dynamic' exports.

    • @mateuszhallala1561
      @mateuszhallala1561 3 місяці тому

      And query data straight from the database for every user every single time?

    • @PraiseYeezus
      @PraiseYeezus 3 місяці тому

      @@mateuszhallala1561 no, you can 1) use the cache on a per-function basis with Next.js' cache 2) use the React cache function to do the same as the first option 3) use state/local storage 4) use a timed cache like shown in the video 5) use an external cache like Redis 6) simply let it call your DB every single time, because if you needed the page to be dynamic maybe you're displaying something close to real-time data anyway (plus DBs have their own cache on-disk anyway)
      there's a ton of options depending on what you want

  • @_helloMrKeni
    @_helloMrKeni 3 місяці тому

    if your data on the page is obtained by using fetch() API, you can just set the revalidate in the fetch() API, since revalidating the data-cache will also revalidate the full-route-cache

  • @alexandrmeyer
    @alexandrmeyer 3 місяці тому

    Well, I am struggling with revalidatepath always working in dev mode, and ignoring certain cases in production. Sometimes it requires additional refresh. Still debugging, so didn't come to a conclusion yet.

  • @noeldolan518
    @noeldolan518 2 місяці тому

    V15 should fix a lot of this craziness! 😅

  • @reyghardackernen7213
    @reyghardackernen7213 2 місяці тому

    So I'm not the one confused about all of these things