“use cache” NextJS’s latest take on data caching

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

КОМЕНТАРІ • 59

  • @EpilefRodriguez
    @EpilefRodriguez Місяць тому +5

    Thank you for taking the time to share your expertise-it's greatly appreciated!

  • @jamesbotwina8744
    @jamesbotwina8744 Місяць тому +1

    Thanks!

  • @bernardyamoah1284
    @bernardyamoah1284 Місяць тому +3

    Finally. Been waiting for this demo

  • @katanaut
    @katanaut Місяць тому +2

    Thanks Jack. We love you.

  • @ashleytwo
    @ashleytwo Місяць тому +3

    Thanks for this clear and detailed explanation

  • @mortezatourani7772
    @mortezatourani7772 27 днів тому +1

    Like always enjoy the content.

  • @frostmichael8360
    @frostmichael8360 Місяць тому +3

    This sharing deserves a lot of visibility, thk you !

  • @UnderstandingCode
    @UnderstandingCode Місяць тому +2

    Awesome video!

  • @ibrahimblahblahyapyap
    @ibrahimblahblahyapyap 2 дні тому

    Jack, how do you get your Terminal @3:31 to look so bloody awesome?

  • @feldinho
    @feldinho Місяць тому +2

    What's the easiest way to tell fetch to always honor the cache control headers from the API? Would that be ergonomic when using API routes? As a backend guy, it feels more intuitive to let the data owner (the API) tell for how long it should be cached.

  • @umarjawhar8
    @umarjawhar8 22 дні тому +1

    great video.

  • @azure346
    @azure346 Місяць тому +1

    What a great video ⚡

  • @prashlovessamosa
    @prashlovessamosa Місяць тому +2

    Thanks this is so helpful

  • @DaviLimadeMedeiros
    @DaviLimadeMedeiros Місяць тому +1

    It'd be nice if the ProNextJS course mentioned had a deep diver section on Middleware, e.g. setting cookie on request (not response) is not trivial and not documented

  • @JoeBoo532
    @JoeBoo532 29 днів тому

    Hi, are you planing on doing black Friday deal on your next js pro course ? :)

  • @irfansaeedkhan7242
    @irfansaeedkhan7242 Місяць тому +1

    thanks for sharing

  • @kamilkacperek91
    @kamilkacperek91 Місяць тому +7

    Honestly, the standard, non experimental version feels more intuitive for me.

  • @mainakdas5819
    @mainakdas5819 Місяць тому

    Random thought, suppose I have a endpoint that query CMS to get 10 items and query backend to get the price of available 8 items. Now I’ve to merge and filter both the API to get the data ans price of those 8 items only. How do you cache that scenario?

  • @mavenwander2374
    @mavenwander2374 Місяць тому +1

    Nothing beats Pages Router caching. So clear and simple.

  • @creatorsremose
    @creatorsremose Місяць тому

    Where does requestTime come from? Is that a Next augmentation?

    • @jherr
      @jherr  Місяць тому +1

      No. It’s returned from the API.

  • @PeterSahanaya
    @PeterSahanaya Місяць тому +1

    hey jack, is the caching with "use cache" works on vps? not just on vercel

    • @jherr
      @jherr  Місяць тому

      Yes. Caching works on VPS.

    • @adityaanuragi6916
      @adityaanuragi6916 Місяць тому +1

      ​@@jherr VPS? (sry I'm noob)

    • @jherr
      @jherr  Місяць тому +1

      @ no worries. Virtual Private Server. Basically a box on the internet that you install on and go. Really he means any non-Vercel deployment.

    • @adityaanuragi6916
      @adityaanuragi6916 Місяць тому

      @jherr like EC2? (thx for da help)

    • @jherr
      @jherr  Місяць тому

      @ yes. EC2 or ECS or EKS or just a $4.99/mo hosting site.

  • @belgarat0
    @belgarat0 Місяць тому

    In my app i have tons of data fetching use cases(around 100), do i need to actually place 'use cache' and the timer on every single one?

    • @codefinity
      @codefinity Місяць тому

      🤔 you can keep all in a single ‘lib’ ‘fetchers’ file and pop the directive at the 🔝❔
      But, that would apply same caching behavior for all!

    • @feldinho
      @feldinho Місяць тому

      Out of curiosity, how do you do it currently?

  • @astralking6162
    @astralking6162 Місяць тому

    As i know, pages router had a thing like on-demand ISR, was a cool feature, i was implementing it to my project)

    • @jherr
      @jherr  Місяць тому +1

      Again though, the ISR granularity is a whole page.

    • @astralking6162
      @astralking6162 27 днів тому

      @@jherr Yes, but with on-demand ISR there was no problem. that the product was updated from the admin panel, but it has not yet been updated on the site, since revalidate is set to 60, so for another 60 seconds the product will have outdated information, but with on-demand ISR you could set revalidate to 24 hours and not worry that the product will not be updated, because as soon as the product was updated, a request was made to the product page and it was immediately updated)

    • @jherr
      @jherr  27 днів тому +1

      @@astralking6162 But with ISR you can't control what data on the page is cached at what level. You could send along cache control headers from the API. But if you're doing ISR with server functions those don't have persistent fetch cache. So you'll always be updating all the data at the fastest SLA.

  • @funkjoker
    @funkjoker 27 днів тому

    Is this kinda PPR from aside?

    • @jherr
      @jherr  26 днів тому

      Maybe? I'd have to think about that for a bit.

  • @amershboul9107
    @amershboul9107 Місяць тому +1

    you are the best !

  • @MrZiyak99
    @MrZiyak99 Місяць тому

    you technically could wrap the cached components in suspense as well correct? it’s just not mandated cause the loading speed would be really fast?

    • @jherr
      @jherr  Місяць тому

      Yeah, absolutely.

    • @SaltyRain1
      @SaltyRain1 День тому

      @@jherr Is it a good practice to always wrap server components that are asynchronous with suspense, even that they are cached. Or it is overwhelming? No clear explanation about that in the official docs

    • @jherr
      @jherr  День тому

      @@SaltyRain1 I can't say for sure. But it just falls back onto the semantics of Suspense regardless of the whether it's cached because the cache might not hit. So do you want the render to block on that component or not, in the case of a cache miss. That's the question.

  • @couragic
    @couragic Місяць тому

    4:35 Prices are getting higher even in study projects 😢😊

  • @rijkvanwel
    @rijkvanwel Місяць тому +2

    Honestly, of late it feels there is no one at the wheel at Vercel in terms of API design. What a mess. Great explanation though

  • @tririfandani1876
    @tririfandani1876 Місяць тому

    we need 1 more explanation, the react built in `cache` experimental function

  • @hamdaniash-siddiq5021
    @hamdaniash-siddiq5021 Місяць тому

    well, anything that includes so called 'cache" is something to be aware of. Its a trade between speed and server workload.. Cahing !== optimization.

  • @CanisLatransMedia
    @CanisLatransMedia Місяць тому

    Is it me or Jacks lips are always not synced properly 😅 Content good as always tho!

  • @dzigizord6567
    @dzigizord6567 Місяць тому +25

    whoever pushed for "use cache" api should be fired. why in the world would you use magic strings for anything. magic strings that influence how infra behaves no less. using normal functions were not cool enough?

    • @adityaanuragi6916
      @adityaanuragi6916 Місяць тому +1

      I've never used next before, but a directive seems like an absurd way of going about it
      Why not just a function?

    • @codefinity
      @codefinity Місяць тому

      Directives have 🫘 there and even JS ‘use strict’ from back in the day. Not that 🧐.
      If you don’t 👍🏾, don’t use it.

    • @codefinity
      @codefinity Місяць тому

      @@adityaanuragi6916Maybe use the tech for s bit first before 💩-posting and/or hating on it.

    • @feldinho
      @feldinho Місяць тому +1

      @@codefinity It was a bad idea back then, too.

    • @TianYuanEX
      @TianYuanEX Місяць тому +1

      Just use tanstack; infinitely better DX with far less gotchas and black box stuff in it...