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

Поделиться
HTML-код
  • Опубликовано: 10 фев 2025

Комментарии • 61

  • @EpilefRodriguez
    @EpilefRodriguez 2 месяца назад +6

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

  • @jamesbotwina8744
    @jamesbotwina8744 2 месяца назад +2

    Thanks!

  • @bernardyamoah1284
    @bernardyamoah1284 2 месяца назад +3

    Finally. Been waiting for this demo

  • @mavenwander2374
    @mavenwander2374 2 месяца назад +2

    Nothing beats Pages Router caching. So clear and simple.

  • @frostmichael8360
    @frostmichael8360 2 месяца назад +3

    This sharing deserves a lot of visibility, thk you !

  • @ashleytwo
    @ashleytwo 2 месяца назад +3

    Thanks for this clear and detailed explanation

  • @katanaut
    @katanaut 2 месяца назад +2

    Thanks Jack. We love you.

  • @mortezatourani7772
    @mortezatourani7772 2 месяца назад +1

    Like always enjoy the content.

  • @UnderstandingCode
    @UnderstandingCode 2 месяца назад +2

    Awesome video!

  • @prashlovessamosa
    @prashlovessamosa 2 месяца назад +2

    Thanks this is so helpful

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd Месяц назад

    Thank you so much for the video

  • @azure346
    @azure346 2 месяца назад +1

    What a great video ⚡

  • @umarjawhar8
    @umarjawhar8 2 месяца назад +1

    great video.

  • @feldinho
    @feldinho 2 месяца назад +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.

  • @kamilkacperek91
    @kamilkacperek91 2 месяца назад +7

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

  • @JoeBoo532
    @JoeBoo532 2 месяца назад

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

  • @ibrahimblahblahyapyap
    @ibrahimblahblahyapyap Месяц назад

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

  • @DaviLimadeMedeiros
    @DaviLimadeMedeiros 2 месяца назад +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

  • @irfansaeedkhan7242
    @irfansaeedkhan7242 2 месяца назад +1

    thanks for sharing

  • @ShamunkhatriEC
    @ShamunkhatriEC Месяц назад

    Really good video but what about the client-side data caching? I wanted data caching for at least a specific time. like if I move between routes it should not recall that API again instead show the cached data.
    I have basic implementation of react query but seems like it is not working out. even explicitly mentioned staleTime property.
    If you/anyone here know how to do this then let me know

  • @mainakdas5819
    @mainakdas5819 2 месяца назад

    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?

  • @astralking6162
    @astralking6162 2 месяца назад

    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  2 месяца назад +1

      Again though, the ISR granularity is a whole page.

    • @astralking6162
      @astralking6162 2 месяца назад

      @@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  2 месяца назад +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.

  • @rijkvanwel
    @rijkvanwel 2 месяца назад +3

    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

  • @belgarat0
    @belgarat0 2 месяца назад

    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 2 месяца назад

      🤔 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 2 месяца назад

      Out of curiosity, how do you do it currently?

  • @amershboul9107
    @amershboul9107 2 месяца назад +1

    you are the best !

  • @creatorsremose
    @creatorsremose 2 месяца назад

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

    • @jherr
      @jherr  2 месяца назад +1

      No. It’s returned from the API.

  • @MrZiyak99
    @MrZiyak99 2 месяца назад

    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  2 месяца назад

      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.

  • @funkjoker
    @funkjoker 2 месяца назад

    Is this kinda PPR from aside?

    • @jherr
      @jherr  2 месяца назад

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

  • @PeterSahanaya
    @PeterSahanaya 2 месяца назад +1

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

    • @jherr
      @jherr  2 месяца назад

      Yes. Caching works on VPS.

    • @adityaanuragi6916
      @adityaanuragi6916 2 месяца назад +1

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

    • @jherr
      @jherr  2 месяца назад +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 2 месяца назад

      @jherr like EC2? (thx for da help)

    • @jherr
      @jherr  2 месяца назад

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

  • @couragic
    @couragic 2 месяца назад

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

  • @CanisLatransMedia
    @CanisLatransMedia 2 месяца назад

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

  • @tririfandani1876
    @tririfandani1876 2 месяца назад

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

  • @hamdaniash-siddiq5021
    @hamdaniash-siddiq5021 2 месяца назад

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

  • @dzigizord6567
    @dzigizord6567 2 месяца назад +26

    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 2 месяца назад +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 2 месяца назад

      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 2 месяца назад

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

    • @feldinho
      @feldinho 2 месяца назад +2

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

    • @TianYuanEX
      @TianYuanEX 2 месяца назад +1

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