Fast HTTP Caching With Angular HTTP Observables

Поделиться
HTML-код
  • Опубликовано: 19 июн 2018
  • Tired of waiting for your network requests to come back? Use the power of Angular's HTTP Observables combined with RxJS and your browser's local storage to automatically serve up a locally cached version that quietly gets replaced by real data as soon as the network request is finished.
  • НаукаНаука

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

  • @ganeshacharya234
    @ganeshacharya234 4 года назад

    Super awesome! please dont stop sharing such neat tricks :)

  • @peterl1699
    @peterl1699 6 лет назад +1

    Great tutorial and great lvl on difficulty. Greetings from Sweden

  • @fitigued
    @fitigued 4 года назад +1

    Excellent video, very clear and easy to understand; many thanks Steven.
    The only thing I would do differently is declare the _repos_ observable as _private repo$: Observable;_

  • @tinashecheuka7874
    @tinashecheuka7874 5 лет назад

    Dude you are really Awesome.Thank you for your post. It saved me a day of struggling to find a way to load Api call results properly into my carousel because results where coming asynchronously

  • @nadhirfalta7002
    @nadhirfalta7002 6 лет назад

    Great video, Thank you Stephen!

  • @themarksmith
    @themarksmith 6 лет назад

    Excellent video - thank you!

  • @volkerreichel2285
    @volkerreichel2285 6 лет назад

    Nice video. Easy to understand.
    To everybody who is wondering why the Http GET appears two times in the network log.
    The async pipe in the components html subscribes a second time which causes the second request to be send.
    One might easily forget about this side effect of async but your server has to do twice the work.
    Recommendation: avoid listening to observables in your templates.

  • @mateja176
    @mateja176 6 лет назад +6

    Simple but excellent, perhaps add distrinctUntilChanged and shareReplay into the mix

  • @kwanxyz
    @kwanxyz 4 года назад

    awesome demo...great video

  • @daniellaerachannel
    @daniellaerachannel 6 лет назад

    you're a hero! more tuts please! thanks

  • @maximprosv
    @maximprosv 5 лет назад +4

    In your approach you make 2 http calls, one from async, second from subscribe, please add some info about this flaw

  • @radovansurlak7445
    @radovansurlak7445 4 года назад

    Thank you a lot, great video :)

  • @saurabhshinde1855
    @saurabhshinde1855 3 года назад

    great video!! Thank you so much

  • @reidyoung298
    @reidyoung298 6 лет назад +6

    Hey Steven, thanks for the helpful tutorial. A couple ideas, when you review concepts, will you please make sure they're all on the screen? At one point you do a small code review without scrolling through some of the code. Not a big deal, of course, it just makes it easier on the viewer. In the same way, when you say "and there it is" around @9:07, will you please be careful to point out what you mean in those instances? I'm a little lost about what I'm aiming to see. The localhost request having a 304 status? It would be great if you can answer and better if this comment helps others to comprehend even more of your great content. Cheers and thanks for another wonderful video!

    • @reidyoung298
      @reidyoung298 6 лет назад +1

      Oh, got it now. Took me a few viewings. I hate to be so picky about the language. I'm newer to Angular so little pieces of a tutorial like that one can trip me up just a bit. "There it is" refers to the cached data showing in the view prior to the HTTP request resolving.

  • @zephyr8933
    @zephyr8933 6 лет назад

    Awesome video. Thanks for sharing. May I ask what chrome DevTools theme you're using?

  • @anandjmc88
    @anandjmc88 4 года назад

    thanks, man nice video

  • @heiko3169
    @heiko3169 4 года назад +3

    Hi, even though it may not make any difference in this small project, you should NEVER EVER put things like HTTP requests into the constructor. It's bad practice and no one should "learn" it that way just because he sees it here and doesn't know better!
    You should also add an advise that the localStorage of the browser has limitations and thus cannot be used to put each and everything into it, whenever someone wants to cache something (to cache larger portions of data, the IndexedDB is there for that).

    • @mateuszswiderski5561
      @mateuszswiderski5561 Год назад +2

      Sorry, but What you were talking about 3 years ago bro xD. I Hope you got some more knowledge about dep injection and difference between cache and localstorage. 1 minutę later: OMG he really used localstorage what the heck

    • @randomgreatness2298
      @randomgreatness2298 Год назад

      Well, Im just not finna watch this video then

  • @paulfx5019
    @paulfx5019 5 лет назад

    Great tuts Stephen, any chance we could get a tut on applying Fast HTTP Caching to Angular Material Table DataSource via a service?

  • @akab211
    @akab211 4 года назад +3

    I really like massaging the data.

  • @adityarawat2966
    @adityarawat2966 2 года назад

    You can very well use this video as an asmr

  • @vidyasagarveluvarti7308
    @vidyasagarveluvarti7308 5 лет назад

    Nice 👍, what are vs code extensions do you used ??

  • @csgokul
    @csgokul 6 лет назад

    Hi Steven .. this is a great video .. How would we cache images in angular when using firebase storage .. ?

  • @mishraTeaches
    @mishraTeaches 11 месяцев назад

    i think best approach is to use Map,rather than storing data,like if the usecase is user can reload the page also,then only we can use localStorage,because storing data in localstorage is not good option.
    With map,we can store data in key,value pair and then we can check whether data is already present or not

  • @walidrachad1912
    @walidrachad1912 4 года назад

    good job

  • @reidyoung298
    @reidyoung298 6 лет назад

    Is there any reason to use map versus pluck?

  • @michaldevpl
    @michaldevpl Год назад

    nice example of caching - kind of :)

  • @ankychavan4392
    @ankychavan4392 Год назад

    We need local storage setitem to set it into local storage right how can you store without using setitem

  • @msworddocu
    @msworddocu 4 года назад

    Hey, I have a token that I wanna cache. But this token will. Keep changing evry 5 minutes.. How can we cache this?

  • @valikonen
    @valikonen 3 года назад +2

    Yes, but in practice you'll get same data, it's never updated. In my opinion in reality this approach will not be good.

  • @mayurgudi381
    @mayurgudi381 3 года назад

    👌🏻👌🏻👌🏻

  • @bizmarinainfo1808
    @bizmarinainfo1808 2 года назад

    I did it exactly as you illustrated, but the request is still taking ages. any thoughts what could have gone wrong?

  • @user-rw8nm6wc4z
    @user-rw8nm6wc4z 5 лет назад

    It is cool

  • @hadirahmani7943
    @hadirahmani7943 2 года назад

    thanks so much, so how can we invalidate cache?

  • @SudhanshuJainWest
    @SudhanshuJainWest 5 лет назад +1

    Hey, the network tab shows 2 calls to repositories, why are we making 2 calls ?

    • @nikolaarsenovic1731
      @nikolaarsenovic1731 5 лет назад

      First request is not GET it is OPTIONS. Then if GET is allowed it will make get request

    • @kflo411
      @kflo411 3 года назад

      Actually @Nikola Arsenovic, it is a redundant call. Both are GETs (see 9:37, the first call has a JSON response).
      The reason it is redundant is because he subscribed in 2 places:
      1. in html, via the "async" pipe
      2. on line 24 of the code-behind, via ".subscribe"
      The http Observable needs a "shareReplay(1)" operator in the .pipe( ) so that both subscriptions use the same result. Otherwise, they are independent.

  • @somedev1553
    @somedev1553 4 года назад

    Will this work on images?

  • @samj5581
    @samj5581 3 года назад

    I still seeing API calls , how that can happen ?

  • @lonewolf2826
    @lonewolf2826 3 года назад

    how to set cache key ?

  • @windmillcode9189
    @windmillcode9189 3 года назад

    I was looking on how to cache POST Requsts beautifal

  • @xingyoong7129
    @xingyoong7129 4 года назад

    good video. But voice is too low

  • @yoshirok
    @yoshirok 3 года назад

    Is localStorage safe? 🤔

    • @NassLyy
      @NassLyy Год назад

      You encrypt all the data stored In localStorage

  • @sanelisogladstonesimelane1359
    @sanelisogladstonesimelane1359 4 года назад

    I have always used local storage to cache my data lol, shocking how I received these project from this company and they catch their data on another server :(

    • @heiko3169
      @heiko3169 4 года назад

      localStorage has some limitations! Unfortunately the author of this video didn't mention that as advise.