Intro to In-Memory Caching in C#

Поділитися
Вставка
  • Опубліковано 7 січ 2025

КОМЕНТАРІ • 170

  • @jankool01
    @jankool01 3 роки тому +15

    I like these short videos with simple and complete examples.

  • @lastonedown
    @lastonedown 3 роки тому +8

    Best tutorial I have found for caching. Great work Tim and keep the videos coming.

  • @edwhoa
    @edwhoa 2 роки тому +2

    I always thought that caching was a mess to integrate. After seeing your video, it took literally 5 minutes to make it work.
    Thanks a lot mate, you're amazing!

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      I am glad it was helpful. Caching itself is actually fairly easy. The difficulty will come in when it comes to deciding when to invalidate the cache and get fresh data.

    • @edwhoa
      @edwhoa 2 роки тому

      @@IAmTimCorey Exactly. Some people suggest to Dispose and create a new fresh instance.. but I don't think it's a valid solution.

  • @josef2577
    @josef2577 3 роки тому +11

    Hi Tim, first I have to say thank you so much for everything you did and are doing for me and for literally thousands of developers around the world!
    I have one very small critique. I'm not a native English speaker, and sometimes I feel like a word you say every few sentences gets lost on me, almost as if you're saying the word in shorthand form, perhaps because you're very used to the language.
    Once again thank you very much Tim, you are a true teacher.

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +5

      I am glad you are finding my content valuable. Thanks for the note. I will try to pay attention to that.

  • @umer.on.youtube
    @umer.on.youtube 3 роки тому +3

    22:05 "one of those 'Tim's Gonna Make Sure You're Clear On This' section" Haha! 😁Love it.
    Thank you Tim for the clarity and depth. Your efforts are more than commendable in this field! 👍

  • @MINECRAFTLORDMASTER
    @MINECRAFTLORDMASTER 3 роки тому

    You didn't lie when you responded to my comment just the other day telling me that you would do a video on this soon!! Your the man!

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      Yep, it was already in progress.

  • @vittoriomorellini1939
    @vittoriomorellini1939 3 роки тому +2

    Very interesting. Usually backend is stateless. This is a way, better way to make it to manage also state, without using static statement that is dangerous in web applications

  • @ДенисМалахов-к9э
    @ДенисМалахов-к9э 3 роки тому +2

    Thanks for lesson.
    I like that you speak so clearly. So i can understand all the things

  • @nadervaghari51
    @nadervaghari51 3 роки тому +3

    oh Tim you're awesome! I can't stop watching your tutorials, I 'm gonna cancel my Netflix subscription! 👌😊

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +1

      I am glad you are enjoying them.

  • @bipinchandrakant3085
    @bipinchandrakant3085 2 роки тому +1

    Awesome! Thanks a lot, Tim for the detailed tutorial. To me, your tutorials are unique because you explain
    How to use
    When it should be used
    When it should not be used
    and also mention the alternative tool/approach.
    Today I learned about In-Memory Cache and Redis.

  • @ko-jiro5971
    @ko-jiro5971 3 роки тому +2

    At the right time! I was just looking at some literature on this subject. Thanks Tim! 👍🏽

  • @teriyakov
    @teriyakov 2 роки тому

    That was shockingly easy to implement. Thanks as always. Keep up the great work.

  • @AliMustafa-xp8ih
    @AliMustafa-xp8ih Рік тому

    Thank you very much Tim for every thing you are sharing with us , Keep up PLEASE

  • @CRBarchager
    @CRBarchager 3 роки тому +1

    Most definately something I could see myself using in one of my projects I have.

  • @emon1019
    @emon1019 7 місяців тому

    As always, good stuff. Thanks Tim

  • @TrevorNewsome
    @TrevorNewsome 3 роки тому

    I wasn't aware of the Microsoft caching extension. Thank you and good advice.

  • @Kazem_Javadi
    @Kazem_Javadi 3 роки тому +1

    Thank you Tim Corey 😊🙏🏻
    This video was very good 👍🏻

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      You are most welcome. Thanks for watching.

  • @AmirAliZargaran82
    @AmirAliZargaran82 7 місяців тому

    thank you very much for this excellent and clear intro

  • @dasfahrer8187
    @dasfahrer8187 3 роки тому

    1:56 ... I have no idea what was said there, but all I heard was 'we're gonna start ripping ass right away' and now I can't unhear it 🤣🤣🤣

  • @billyarredondopucp
    @billyarredondopucp 2 роки тому

    Hi, Tim! It was an excellent explanation; thank you so much!

  • @Noitcereon
    @Noitcereon 3 роки тому +12

    Audio sounds a bit wonkey. Can't put my finger on what it is, though. What you say is still understandable, so it is not a major issue.

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +2

      Yeah, I'm trying to figure out what the issue is.

    • @danervin5138
      @danervin5138 3 роки тому

      @@IAmTimCorey Sounds almost like a directional mic that was pointed the wrong way. Picks up your voice indirectly so it is missing a lot of signal.

  • @pawel89pawel
    @pawel89pawel 3 роки тому

    I am officially calling you psychic I was just thinking of how to do it and here you go a video of how to do it 😂😂😂.

  • @lifeisgameplayit
    @lifeisgameplayit 3 роки тому

    Yet another awesome tutorial from Tim . ; ]

  • @someonesoumya
    @someonesoumya Рік тому

    Thanks TIm , It's a Crystal clear.

    • @IAmTimCorey
      @IAmTimCorey  Рік тому

      You are welcome. I am glad it was helpful.

  • @MayankSharma-qb6hc
    @MayankSharma-qb6hc 2 роки тому

    Thank you Tim for this wonderful video it was really very helpful.

  • @ldiniz_x
    @ldiniz_x 2 роки тому

    Great lesson, Tim! Thanks again.

  • @mohinikadasi5737
    @mohinikadasi5737 2 роки тому

    Nice video. Thanks for detail explanation.

  • @jesusdelarua5995
    @jesusdelarua5995 3 роки тому +5

    Hello Tim. You are a great teacher. I am learning a lot from your courses.
    Do you have any plan for a DEMO on how to implement SSO in Net Core Web apps?
    Thank you.

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +2

      Not in the short term, but that is something I am considering.

  • @DanFlakes
    @DanFlakes 3 роки тому

    This saves alot of dev time now that I don't have to run a redis container every time. (but ofcourse still stick to redis when it comes to heavy caching)

  • @neralem
    @neralem 2 роки тому

    15:30 if you say this is shared across instances...do you mean this is shared between multiples instances of your web application? So if there are 2 instances running to distribute workload, does every instance have it's own cache of employees or do they access all the same? And is this threadsafe?

    • @neralem
      @neralem 2 роки тому

      Nevermind my first question :D Maybe I should watch the whole video^^ Thanks! Awesome video!

  • @ThePholosopher
    @ThePholosopher 2 роки тому

    so helpful, Tim, thank you!!

  • @hari2633
    @hari2633 2 роки тому

    Very nice and good explanation..

  • @jeremyvonhatten5811
    @jeremyvonhatten5811 3 роки тому +7

    Nice caching overview. Can you also talk about the best ways to support apps that have a large amount of data? I think caching is definitely a peice of it, but I would like to migrate a data-heavy winforms/wpf app to blazor and I would like to see how you would go about managing a large set of data (large being 1gb+) and if blazor can even handle data like that without extreme amounts of paging ect...

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +17

      When we build desktop apps, we tend to get a bit lazy with our data because we have such power available to us on the client side. If you think about 1GB of data, and how much content that represents, you will see that it is too much to display to the user. Yes, you might "need" all of that data but the user never sees that much. If we converted 1GB into 200-page books, we would need over 4,000 of them. So when you move to the web (or honestly even before since the same principle is true on the desktop - the web just forces you to work differently), you need to think about what is actually needed. For instance, if you have a list of employees, you probably just need a few pieces of information (name, Id, department, title), not all of the information about an employee. So, you create a query that gets you just that information. Then, you don't need to display all of the employees for your entire organization on the screen at once (even hidden behind a scroll). Load just the records they need to see. That might require you to do multiple queries if they want to scroll manually through the list. You can use the Virtualize panel in Blazor to help make that more transparent. You will have to do some work, but that work should be done in both apps, not just the web app.

    • @simonfarre4907
      @simonfarre4907 3 роки тому +2

      @@IAmTimCorey I see this almost obsessive trait, of wanting to move from desktop to a web environment and it is just crazy to me. In the end, it has little thought for the end user and thinks only about the developer. The user experience will be objectively and measurably worse in a web application, there is no denying this, you even hint at that yourself, one of the many, many reasons.
      Don't move to web because some manager who does not care the slightest about the end user experience wants to use web-devy stuff. Think about the end user and the problem you are trying to solve, instead.

  • @fbodirector7464
    @fbodirector7464 2 роки тому +1

    I use a lot of in memory caching in an older version of .Net. It is very similar to what you are doing here but I do one thing I didn't notice in the video, I clear the cache manually in some circumstances. Adds, Edits, and Deletes of record lists that I have cached for instance. Can you set the value of the cache to null to clear it manually or are you constrained to the expiration datetime?

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      Yes, you can clear the values. Just use the Remove method: docs.microsoft.com/en-us/dotnet/api/system.runtime.caching.memorycache.remove?view=dotnet-plat-ext-6.0

  • @programmer5855
    @programmer5855 3 роки тому +1

    15:00 for Memory Caching

  • @ro2207
    @ro2207 3 роки тому +1

    Hi Tim,
    great Video.
    Do you actually have a video about adding dependency injection into a desktop application?

  • @krishj8011
    @krishj8011 5 місяців тому

    Excellent Tutorial...

  • @aganeto1
    @aganeto1 10 місяців тому

    Why we are transient for DataAccess DI, if all of them would see the same data? Why not singleton too ?

  • @jhanifkara8552
    @jhanifkara8552 2 роки тому

    Which is the best way to cache image url to be downloaded once but displayed in different divs, i have been searching about image url caching in blazor web assemple but to where to find a good source of information.
    To display the images i am using
    I want to catch the image from this div to the use this images in order div without needing to use resorses to downoad the image again in the other divs withe same methodology of backgound-image url.

  • @yanaraldaghestani6305
    @yanaraldaghestani6305 3 роки тому +2

    thanks man it is amazing
    but what about concurrent request for the same cache key
    if two request check the same key they will ask the database twice and set the key twice .
    is there any solution for that ?

    • @guiorgy
      @guiorgy 3 роки тому

      locks? Can't think of anything else

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +1

      Good question. It depends on if this is a problem. First, this probably won't happen often. However, if it does happen, the worst-case scenario is that you call the database twice instead of once and that you overwrite the cache with the second call to set the value. But if that is a serious problem, you could implement a service that does caching in order. Then it could deduplicate requests. I think that's a lot of extra overhead for every call when the problem it is solving has such a low impact.

    • @SuperMarcotorino
      @SuperMarcotorino 3 роки тому

      @@IAmTimCorey I was also wondering about the thread-safety of memory cache... although, tbh, my main concern is about thread-safety of Redis cache, as I intend to use memory cache only in dev environment, and Redis in production.

  • @AMurr-zm4wh
    @AMurr-zm4wh 3 роки тому

    Hi Tim,
    Thanks - I learn something new today. Not in deep, but enough to understand where to look if needed.
    One side question, indirectly related with caching.
    Given relatively big document. Memory is enough to keep it in memory.
    Document are consumed by several threads. Read-only mode.
    And here came a problem:
    - can't have a copy of the document for each thread - too much memory require;
    - can't use pipes for to interact between main storage and thread - too slow;
    Need some kind of common memory shared between threads, but threads are isolated.
    Any sods about how to approach this problem will be appreciated.

  • @TheSjoerd
    @TheSjoerd 3 роки тому

    Good one, thanks! But what is the difference between mem cache and storing the result in a property and refreshing that after x minutes via for instance a Hangfire job? And don't say You won't need Hangfire anymore :) Asking because I want to use some sort of caching in my portfolio app.

  • @vicenzovendetta3443
    @vicenzovendetta3443 3 роки тому

    Wait, your new .NET 6 project already started with the usings without messing with the project file?
    How do I do that?

  • @RussianBananan
    @RussianBananan 3 роки тому +5

    Hi, Tim! As always, great and useful explanation! Sometimes I face the cases, when there is no any predefined timespan for cache to live, but you want the data, which got changed in the database, to be immediately become up-to-date. Is there a way to achieve that? Like, when the data in DB table is changed, some kind of trigger is burned and the data in in-memory cache (or, whatever else) becomes synced to the data in the table.

  • @DutchDJSteel
    @DutchDJSteel 2 роки тому

    Couldn't you use a singleton for the SampleDataAccess?

  • @abdulnaveed4984
    @abdulnaveed4984 2 роки тому

    Hi Tim, Could you please make a video on threading in c sharp ,dotnet core
    in detail

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      The top two results will cover almost all of your threading needs: ua-cam.com/users/IAmTimCoreysearch?query=async

    • @abdulnaveed4984
      @abdulnaveed4984 2 роки тому

      @@IAmTimCorey thank you sir for response

  • @messiah6670
    @messiah6670 10 місяців тому

    Thank you Tim, Great Video, btw can you tell me how can i add that extension which indicates parameter types in Methods .Delay(millisecondsDelay: 3000)

    • @IAmTimCorey
      @IAmTimCorey  10 місяців тому +1

      Here you go: ua-cam.com/video/morBKqtqmso/v-deo.html

    • @messiah6670
      @messiah6670 10 місяців тому

      @@IAmTimCorey thank you again 🙏

  • @michaelshaw9997
    @michaelshaw9997 3 роки тому +1

    Hi Tim, Great tutorial! Do you have any tutorials on automatically repopulating your IMemoryCache from the database after a few hours? I don't have many queries but they are large and the db loads gets new data once a day. I cant quite figure out how its done from stack overflow.

    • @SayWhaaaaaaaaaaaaaaaaaaaaaaat
      @SayWhaaaaaaaaaaaaaaaaaaaaaaat 3 роки тому +1

      HELLO..did you watch the video? he showed it. In method you calling cached data, you should populate it if cache is expired/null. So just read data and put it in cache. so you got auto repupulation.
      If you want auto populate cache even if nobody ask for data - then your idea is dumb and you should not develop apps, because it's dumb to keep data in memory if nobody even asks for it.

    • @michaelshaw9997
      @michaelshaw9997 3 роки тому

      @@SayWhaaaaaaaaaaaaaaaaaaaaaaat Hi Tomas, I did watch the video but I would like to repopulate the data after it expires automatically. My ASP Core app has queries that need 15+ seconds and I cant ask the user to deal with that or do it myself each morning. I have seen examples with PostEvicitionCallbacks and ExpirationTokens that should solve the need but I am having trouble.

  • @Binaural3DSongs
    @Binaural3DSongs 3 роки тому

    Hello tim,
    Can you please help in extending this example with CRUD example? So how value get updates and available to all with caching?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +2

      Watch the Suggestion Site App course here on UA-cam. We will be using in-memory caching in the app.

    • @Binaural3DSongs
      @Binaural3DSongs 3 роки тому

      @@IAmTimCorey
      Ok got it. Thanks

  • @worldinstyle
    @worldinstyle Рік тому

    Oh wow, how I missed ur tutorials. Thank you so much for this. A question: is memorycache thread safe?

  • @MuhammadIshaqkhan-jy8gp
    @MuhammadIshaqkhan-jy8gp 2 роки тому

    Hey Tim!,
    Thank you very much. It's a nice video. I have one quick question. Does the cache affect the worker process memory usage or it is something out of process memory management?

  • @286432531
    @286432531 3 роки тому

    Hi Tim. I love watching your videos. Do you have any video talking about lazy loading ef database model set up ?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      I don't. I don't really cover EF, except for one video.

  • @AS-kw1ob
    @AS-kw1ob 3 роки тому +1

    Do you use another Mic? Quality was better before. Thanks for the vid.

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      Different room and I’m still working through the best setup.

  • @johnotu5610
    @johnotu5610 3 роки тому

    Many Thanks, Tim !

  • @kostasgkoutis8534
    @kostasgkoutis8534 3 роки тому

    Hey Tim, great topic. But what about racing conditions? Shouldn't you recheck with a TryGet just before you tried to set the entry if another thread has set it already on the meantime? Assuming that double-setting of (different) data would be problematic.

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +1

      Worst case, you double-set it. Not a big deal, since if you didn't have caching then you would be getting that data every time. If your data would change based upon the new call then you shouldn't be caching the data.

  • @RANVEER.4321
    @RANVEER.4321 2 роки тому +1

    Hi ,
    I am your huge fan.
    However I have one silly question.
    Is it in memory cache of server or the browser (client) ??

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      It is in the memory of the computer running the application. So for most web projects, that means the server. The exception would be for Blazor WebAssembly projects, where it would be in the client's memory.

  • @alikemalkulful
    @alikemalkulful Рік тому

    Hello Tim, Very informative and clean explanation. Thanks.. What if any user adds a new Employee to database? Shall we remove and create the new cache or is there a way to edit the cache?

    • @IAmTimCorey
      @IAmTimCorey  Рік тому

      Typically the best option is to invalidate the cache and reload it.

  • @jasminer8455
    @jasminer8455 Рік тому

    Would this work for caching data for a loooooong form? Assign the fields to the output and then add to the memory
    cache after X minutes?

    • @IAmTimCorey
      @IAmTimCorey  Рік тому +1

      Typically forms are on the client-side and this caching is server-side, so you would need to look at a client-side cache like SessionStorage or LocalStorage unless you wanted to post a partial form to the server.

  • @izikon1978
    @izikon1978 3 роки тому

    Hi. Thanks for the tutorial.
    One question. When handling with large data and many users. A thread problem can happens? Meaning 2 threads think the orders are null?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      Yes, between the time you check for records and when you set the records in the cache, someone else can do the same thing. That would result in multiple people doing the data lookup from the database. That's not a huge deal in most cases. If it is, you can use LazyCache to wrap this so that you only get one database read.

  • @beepIL
    @beepIL 2 роки тому

    Hi Tim,
    Assuming the same request happens in a short amount of time,
    lets say the cache is empty at this point.
    Now lets say request A is called to get employees and it takes 10 seconds.
    but before 10 seconds pass, after about 6 seconds, another request was made - ie: request B
    Now since request A and request B should return the same thing, there is no point in processing both.
    So i want request A to process, and have request B wait for the result to be populated in the cache then return the cached result.
    How would you go about implementing something like this?

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      That would be a lot of work for little return. You could create a class with a completion event and an indicator when the class has been activated. Then, the first call activates the class and subscribes to the completed event. Every subsequent call could subscribe to the event only, knowing the call is in progress. However, that's a lot of additional overhead when it usually isn't necessary. Caching isn't about never making a duplicate call. It is about reducing the number of calls. You should be able to function without caching. In the case of your 10-second call, the first thing I would do is work on reducing that number. 10 seconds is a LONG time to wait for something. If you could add some complexity to reduce that call to 3 second, the number of duplicate calls you would have would go down and the overall experience for everyone would be better. Another option for long-running calls like that is to only let the system kick them off. Always work from the cache and have the system handle refreshing it in the background. That way, you never have duplicate calls, and the initial call happens on system load, so no one is ever waiting those 10 seconds.

  • @gouthamk378
    @gouthamk378 2 роки тому

    Great Video, I have one doubt can we use combination of memory caching and also response caching at a time on the same action!

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      Yep. You will just need to manage your cache invalidation periods so you don't cause an issue.

  • @chargurukar
    @chargurukar 2 роки тому

    Hi Tim,
    Thanks a lot for the detailed info with examples.
    Does the cache stored on RAM or on disk?

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      In RAM, although if the memory pressure on your web server, your web server might offload some to disk. However, that is a transparent process to you.

  • @erosnemesis
    @erosnemesis 2 роки тому

    Using tryget would be the preferred way. Much cleaner too.

  • @legittaco4440
    @legittaco4440 3 роки тому

    If you have a website and your using memory cache, does it cache the memory on the person using the websites computer or does it cache it on the servers memory?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      On the server unless you are running Blazor WebAssembly, which runs on the client's machine.

  • @fieryscorpion
    @fieryscorpion 2 роки тому +1

    If you could get videos under 20 minutes, that'd be so much better.
    Thank you!

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому

      Time isn't really the issue here, it is the content. So what content are you hoping to cut? These videos are about preparing you to use a topic in the real world, not just a "here is what this topic is"-type. I do have the 10-minute training series for those types of videos.

  • @MuthuNadar
    @MuthuNadar Рік тому

    Hi Tim, how to decide how much data I can store in memory. I'm I cannot just store millions of record.

    • @IAmTimCorey
      @IAmTimCorey  Рік тому

      Store the data the user will actually need. For instance, do they actually need a million records? If so, caching probably needs to happen on Redis or something similar. Another test is what are they coming back to repeatedly?

  • @girornsveinsson7970
    @girornsveinsson7970 3 роки тому

    What if you know the data is not going to change? Is there any reason in such cases to use the cashing rather than just load it in a singleton service?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +1

      Memory pressure. If your memory pressure gets too high, you can flush the cache. That's not as easy with a singleton.

  • @tosinakinyemi3948
    @tosinakinyemi3948 3 роки тому

    Thank you Tim.

  • @jeremyleff
    @jeremyleff 3 роки тому

    What are the advantages of using this over say the Azure Redis service?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      In memory is quick and for small jobs. Redis is for when those small jobs get larger.

  • @olgakhomyakova4760
    @olgakhomyakova4760 3 роки тому

    Is this subject included in your new mastercourse update?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому

      No, this is outside the scope of the C# Mastercourse.

  • @adityarane2758
    @adityarane2758 3 роки тому

    Can you please make some videos on xamarin mobile app development or apache cordova ?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +1

      I will add it to the list. Thanks for the suggestion.

  • @esmail9189
    @esmail9189 3 роки тому

    What if I have an event that tells me that an employee has been added, changed or deleted so I can expire the cache Instead of giving a short time and the data is still not changed
    is it a good practice?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +1

      Sure, just set the cache in that event and it will overwrite the current list.

    • @esmail9189
      @esmail9189 3 роки тому

      @@IAmTimCorey Thank you so much

  • @petropzqi
    @petropzqi 3 роки тому

    Great video

  • @monkeycrunch9324
    @monkeycrunch9324 11 місяців тому

    Humbly, thank you. :)

    • @IAmTimCorey
      @IAmTimCorey  11 місяців тому +1

      You are welcome.

    • @monkeycrunch9324
      @monkeycrunch9324 11 місяців тому

      @IAmTimCorey hey, mr Corey.. I am a South African that cannot afford your full courses... How's about a give away video? Hmmm 😁😁

  • @nadervaghari51
    @nadervaghari51 3 роки тому

    May I ask you what is difference if I create a Singleton repository and load all data into some private field inside the class? can I imitate In Memory Caching using this approach? because every hour first I check the data Count first if there are something added to my data then I will reload my repository again

    • @AMurr-zm4wh
      @AMurr-zm4wh 3 роки тому

      > because every hour ... I will reload
      You can write... but do you need to write something? All already written and need just set 1 hour timeout.
      > if there are something added
      You can update your cache any time you want. It just hashtable in the memory - use the same key and replace the object.

    • @nadervaghari51
      @nadervaghari51 3 роки тому

      @@AMurr-zm4wh if we set the Memory Expiry to 1 hour then after 1 hour we need to reload again (IO cost) but if I check just count of records every hour maybe I don't need to reload again for a couple of hours and it means less IO cost (I need to add new records to my pool only)

    • @AMurr-zm4wh
      @AMurr-zm4wh 3 роки тому

      @@nadervaghari51
      Ok.
      Set 2 hour timeout and update cache in 1 hour. Take object out of the cache, add if you have something to add to the object and put it back into cache - this will reset the timer.
      In this way you not need to write any additional code.

    • @nadervaghari51
      @nadervaghari51 3 роки тому

      @@AMurr-zm4wh but the main question was can we use Singleton fields in place of In Memory Cache or not?

    • @AMurr-zm4wh
      @AMurr-zm4wh 3 роки тому

      @@nadervaghari51
      Yes, you can. At least I use it in the past in global.asax - there was no other way at time.
      But main question is different - Why do you want to write and support additional code in place where nothing need to be written?

  • @memsom
    @memsom 3 роки тому +1

    The title is slightly misleading. This is not C# in general, it is a specific use case stuck in the web mindset. Can you show us how this applies, for example, to WPF or maybe even Xamarin?

    • @IAmTimCorey
      @IAmTimCorey  3 роки тому +1

      It is C# in general. I talked at the end about how you would use it in a desktop app.

  • @jhanifkara8552
    @jhanifkara8552 2 роки тому

    Hi can Imemorycaching be used in webassmbly?

    • @IAmTimCorey
      @IAmTimCorey  2 роки тому +1

      I believe so. Just remember that you are storing it on the client's machine so it will be client-specific.

  • @LoverOf_Knowledge
    @LoverOf_Knowledge Рік тому

    Good job

  • @govindagrawal3325
    @govindagrawal3325 3 роки тому

    How can I make it thread safe??

  • @_rachid
    @_rachid 9 місяців тому

    Thank you!

  • @cw6692
    @cw6692 3 роки тому +1

    Sound is awful. I started to watch and had to switch off.

  • @DDDD-rr6uo
    @DDDD-rr6uo Рік тому

    The way how your explain caching here is much better than in your paid course webapi about caching, like here you even expain with blazor just like in real world so much better but WHY? @IamTimCorey. I Thought paid course could me litle bit more like this?

    • @IAmTimCorey
      @IAmTimCorey  Рік тому +1

      The course isn't about in-memory caching. The course is about the API project template. We cover a LOT of ground in that course, but we don't go into depth on things beyond the scope of the course. So yes, you will find more in-depth topics on this channel or in other courses that are more specific to the topic you are looking into. The API course goes into depth on API, not on all of the connected items. Otherwise, it would be a MASSIVE course. Also, the primary purpose of a course is to lead you down the path of learning a technology in a structured, ordered manner. That is the main benefit of the course. There will always be more depth to go into, more things to learn, and more areas to grow in after you gain the foundational knowledge of the topic.