Distributed Caching In ASP.NET Core With Redis | Introduction

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

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

  • @MilanJovanovicTech
    @MilanJovanovicTech  2 года назад +8

    Get the source code for this video for FREE → the-dotnet-weekly.ck.page/redis-cache
    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

  • @EmptyGlass99
    @EmptyGlass99 2 года назад +7

    Once again you provide a concise yet comprehensive explanation of everything you're doing. You are producing an excellent series of videos.

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

    Nice introduction! Next... handling cache invalidation/expiry!

  • @MarcusKaseder
    @MarcusKaseder 2 года назад +30

    Be careful! while updating the cached value. Attaching to the DbContext is not enough. You must invalidate the cached value while saving (Unit of work). Otherwise all subsequent Get request will get the old Member value from the cache and not the updated one.

  • @AbuBakrSadiqi-b7t
    @AbuBakrSadiqi-b7t Год назад +1

    I can say for sure it is a a comprehensive explanation. thanks for everything you are doing. Can you start a playlist for unit testing, integration testing

  • @vahidghamari-ug8bn
    @vahidghamari-ug8bn Год назад +1

    It was a very practical and complete training, thank you

  • @DermoniS
    @DermoniS 2 года назад +2

    Jako dobar i edukativan sadrzaj. Samo tako nastavi

  • @krzysztofzon8661
    @krzysztofzon8661 2 года назад +4

    JsonSerializerSettings can be additionally stored as a private static field in order to not create a new instance with each request

  • @MXDMND_
    @MXDMND_ 2 года назад +2

    Amazing content Milan. Thank you for your time so much

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 года назад +1

      I have so many great things coming, this doesn't even scratch the surface 😅

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

      @@MilanJovanovicTech will follow you ;)

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

    Hey Milan Nice Explanation about redis and Distrubuted Cache , i was wondering how cache should/will work in case of filterting and pagination can you please make an video about this

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

      You just need to construct your cache keys to include the filter + page number

  • @PelFox
    @PelFox 2 года назад +1

    Interesting about the change tracker for caching, it makes sense. But I havent thought about it so I will need to have another check. In my cached repository it updates as expected without using the attach call.

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

      How does EF know to track it without it being attached?
      Perhaps you explicitly call Update before SaveChanges, which will get the job done

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

      @@MilanJovanovicTech im using a memory cache and not Redis. Maybe its kept tracked in the memory cache, I will dig into this today and potentially remove the cache if that is the case.
      Im not calling Update or Attach.

  • @rishithakur8521
    @rishithakur8521 Год назад +1

    Thank you Milan..
    Query : How to define expiry time or invalidate the cache.. could you please make separate video on to cover this.

  • @nouchance
    @nouchance 2 года назад +1

    Thank you Milan!

  • @HeyBaldur
    @HeyBaldur 3 месяца назад

    Thanks for great tut!
    Is there any way to flush DB but stopping docker?
    Sometimes I want to make tests, and the thing is that redis db still contains X key, but I need to re-build it, is it possible?

  • @Takhralifih
    @Takhralifih 3 месяца назад

    Great video. One question : how to handle cache updates when the data has changed ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  3 месяца назад

      Try this: ruclips.net/video/YdEbD53c8Bs/видео.html

  • @alexlo5655
    @alexlo5655 2 года назад +1

    Hi Milan,
    Thank u for the post.
    I have question.
    Should we handle caching in a Middleware?
    For example if we have something in cache then we return from a call right away.
    If we don't have anything in cache then we hit an entry point and on our "way back" if response is OK (200) we will write to cache.
    Thus we will not mix the busness logic with caching - something like a "decarator" pattern.

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

      That's a good idea, and it's what I'm doing in the video. The CachedMemberRepository is a wrapper around the MemberRepository.

    • @wilsongarciawil
      @wilsongarciawil 2 года назад +1

      I’ve seen people put caches in repositories, mediatr handlers and even controller methods utilizing mediatr (in what looked like an implementation that assumed that cache was part of the “web” layer). I’m too lazy to research where this should fit and I don’t believe that we should always do the things the same way… context always matters. But I tend to put it in mediatr handlers.

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

      @@MilanJovanovicTech ruclips.net/video/Tt5zIKVMMbs/видео.html

    • @alexlo5655
      @alexlo5655 2 года назад +1

      @@wilsongarciawil Nick Chapsas has a video on this
      ruclips.net/video/Tt5zIKVMMbs/видео.html and this is what I mean about middleware.

    • @wilsongarciawil
      @wilsongarciawil 2 года назад +1

      @@alexlo5655 I’ve seen the Nick Chapsas video and it is indeed an awesome implementation. I wouldn’t bother using a decorator if there’s not a lot of business logic in the handler/service/controller. If all you’re doing is accessing your repository and querying data, I would probably add the dependency to the distributed caching right there and do the caching logic. But if you have complex business logic, than the decorator pattern seems a nice way to decouple even more.

  • @balajisairamnarasimhan
    @balajisairamnarasimhan Год назад +1

    Nice stuff thanks for explaining this in a neat format . What is the best pattern you recommend for creating a search engine api ?

  • @modernsanskari4398
    @modernsanskari4398 2 года назад +1

    Hi Milan, Awesome videos and explanation❤
    Can you pls make video on the architecture, design and basic implementation on integration of different CRMs(Zoho/Dynamics, Salesforce, Pipedrive etc) into an web application keeping DDD in mind. How do you maintain consistency in DB, exponential backoff, retry mechanism, rate limiters etc....With EF and DB design.
    Or you can take example of different mailing services too like Gmail, Zoho mail, SMTP.
    It will be very usefull if you make a video from the System design HLD and LLD perspective.

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

      Sounds interesting, I'll see how I can fit it into my content list

  • @salmanshafiq8151
    @salmanshafiq8151 Год назад +1

    Hi Milan, Nice video once again. ❤
    What if the application has more than 200 permissions, should I go for jwt or other process?

  • @sergiom.954
    @sergiom.954 2 года назад +1

    Great job!

  • @SayWhaaaaaaaaaaaaaaaaaaaaaaat
    @SayWhaaaaaaaaaaaaaaaaaaaaaaat 20 дней назад

    Not much about redis, but other 'hacks' was great

  • @hakimedusti
    @hakimedusti 6 месяцев назад +1

    Thank you, that was great

  • @hannahbaker411
    @hannahbaker411 Год назад +1

    hey milan i have a question if ef core caches data by default then using IMemoryCache with ef core is useless right ? i mean if ef core is already doing the job why should we use IMemoryCache?

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

      EF Core doesn't cache data by default. Where did you get that?

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

      @@MilanJovanovicTech oh my mistake then i thought the change tracker do something similar to caching thank you for responding

  • @umutkayatuz9963
    @umutkayatuz9963 2 года назад +1

    What was the reason to use Attach? You just repopulate the entity in the context which is already in the database? What does it do ? For syncing ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 года назад +1

      To make EF change tracking work properly. If we load the entity from cache, EF doesn't know about it

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

      @@MilanJovanovicTech can you give an real world situation example why is it important?
      Is it for syncing in between EF and Redis?

  • @hannahbaker411
    @hannahbaker411 Год назад +1

    great video thank you

  • @vcsoul9052
    @vcsoul9052 Год назад +1

    Hello Milan!
    Isn't it recommended to secure the Redis service? In this way it can be accessed by anybody, right? Can you give me some advice on how to secure it?

  • @viorelbuliga1107
    @viorelbuliga1107 2 года назад +1

    Nice content!

  • @eddypartey1075
    @eddypartey1075 Год назад +1

    Milan, what the difference between _context.Set().Attach(entity) and _context.Attach(entity)?

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

      Both have the same end result, first one is more explicit

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

      Thank you, Milan! Greetings from Russia, serbian brother🖐@@MilanJovanovicTech

  • @mahmoudalaskalany
    @mahmoudalaskalany 2 года назад +1

    I used the interface of distributed cache in a real project but i faced a lot of connection issues when we moved the project to azure cloud and bought azure redis cache so i had to switch back to stackexchange redis nuget to handle the connections better
    I hope if you can explain this issue and if there is a reason for it

  • @Makku293
    @Makku293 7 месяцев назад

    I started to apply Redis to my APIs. This video is perfect, thanks. By the way, What's the name of that theme you're using on VS, please? It's better than the default.

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 месяцев назад +1

      It's ReSharper

    • @Makku293
      @Makku293 7 месяцев назад

      @@MilanJovanovicTech ​ I've been using it since I started programming in C#, and I never knew ReSharper had a theme. Thank you so much for your quick response. Wish you the best.

  • @padnom4991
    @padnom4991 2 года назад +1

    If member is null you return null?
    So the method should be name GetByIdOrDefaultAsync. As in somes comments you said :)
    Thx a lot for your videos!!

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

      Or we can just mark the return type: Member?
      I think that's good enough

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

    Thank you Sir. I have a question. is there any way to use client side caching with redis in dotnet?

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

      What do you mean by "client" here? A web appliaction/UI?

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

      @@MilanJovanovicTech
      Yes. There is this feature in redis documentation.

  • @androidsavior
    @androidsavior 8 месяцев назад

    but it wont serialize entities with so much relations and circular references etc ....
    maybe it is better to cache to on a higher level like caching DTOs or view models ?

  • @Mo-ef9yt
    @Mo-ef9yt 2 года назад +1

    very nice vide.
    Can you make a video on duende server (identity-server 6) with asp.net core web api as backend and blazor server as frontend.

  • @debojitsaha8246
    @debojitsaha8246 Месяц назад +1

    What was that decorate type?

  • @nullentrophy
    @nullentrophy 9 месяцев назад

    How about caching DTOs? Is there any major difference

  • @Andy01010
    @Andy01010 2 года назад +1

    Neat 👍🏻

  • @syedmubeenhussain6317
    @syedmubeenhussain6317 24 дня назад

    Thanks

  • @CesarDemi81
    @CesarDemi81 2 года назад +1

    Why not using Polly.Caching?

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 года назад +1

      I wasn't familiar with it, but I'll see what it can offer

  • @elpe21
    @elpe21 2 года назад +2

    A bit shame you haven't explained why you put Redis into Repository ( DB Engines do have their own cache mechanism ) and not into Controller or QueryHandler.

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

      I definitely forget to mention things from time to time 😅
      Thanks for reminding me, I'll see how I can make it right

    • @wilsongarciawil
      @wilsongarciawil 2 года назад +1

      Certainly not a shame, but a design choice. This is terrific well written code that when tested, can be considered productive ready. I don’t agree with caches in repositories either, but still this is a very good implementation for learning purposes.

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 года назад +1

      @@wilsongarciawil I would probably create a dedicated CacheService that would have a simpler interface, but this is a good start.

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

      @@wilsongarciawil Well, I disagree. A lot of code added whereas there is no gain. Look at response times in the previous video: ruclips.net/video/i_3I6XLAOt0/видео.html . I guess it will be even slower when you manually attach to change tracker ( vs direct to the DB Engine ). Hence it is shame, why Milan has not explain in the video this design choice.

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

      The previous url is without timestamp -> ruclips.net/video/i_3I6XLAOt0/видео.html

  • @harkiratsingh358
    @harkiratsingh358 Год назад +1

    Any cheaper alternative?

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

      RAM?

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

      There is! If you are able to create static singleton object. Store data in it. It offers faster rendering. Offers garbage collection.

  • @techpc5453
    @techpc5453 Год назад +1

  • @techpc5453
    @techpc5453 Год назад +1