No video

Intro to In-Memory Caching in C#

  Рет қаралды 79,247

IAmTimCorey

IAmTimCorey

Күн бұрын

Application performance is important. Just because your application works in development does not mean it will work well once hundreds of people start using it. One key area to look at is data access. Talking to your database can be expensive, especially when the data might not change that often. That's where caching comes in. We can cache that data in a number of ways so that we do not need to keep going back to the database for it. In this video, we are going to look at one of the simplest caching mechanisms in .NET, called In-Memory caching. We will create an application without caching, observe the performance, and then see how caching can improve our performance. We will also discuss the best practices when using in-memory caching.
Full Training Courses: IAmTimCorey.com
Source Code: leadmagnets.ap...
Mailing List: signup.iamtimc...

Пікірлер: 170
@jankool01
@jankool01 2 жыл бұрын
I like these short videos with simple and complete examples.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@josef2577
@josef2577 2 жыл бұрын
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 2 жыл бұрын
I am glad you are finding my content valuable. Thanks for the note. I will try to pay attention to that.
@edwhoa
@edwhoa 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 жыл бұрын
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.
@lastonedown
@lastonedown 2 жыл бұрын
Best tutorial I have found for caching. Great work Tim and keep the videos coming.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@umer.on.youtube
@umer.on.youtube 2 жыл бұрын
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! 👍
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are most welcome.
@vittoriomorellini1939
@vittoriomorellini1939 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
@MINECRAFTLORDMASTER
@MINECRAFTLORDMASTER 2 жыл бұрын
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 2 жыл бұрын
Yep, it was already in progress.
@user-fe9rv8zc5j
@user-fe9rv8zc5j 2 жыл бұрын
Thanks for lesson. I like that you speak so clearly. So i can understand all the things
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Glad to hear that!
@nadervaghari51
@nadervaghari51 2 жыл бұрын
oh Tim you're awesome! I can't stop watching your tutorials, I 'm gonna cancel my Netflix subscription! 👌😊
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I am glad you are enjoying them.
@Noitcereon
@Noitcereon 2 жыл бұрын
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 2 жыл бұрын
Yeah, I'm trying to figure out what the issue is.
@danervin5138
@danervin5138 2 жыл бұрын
@@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.
@ko-jiro5971
@ko-jiro5971 2 жыл бұрын
At the right time! I was just looking at some literature on this subject. Thanks Tim! 👍🏽
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@CRBarchager
@CRBarchager 2 жыл бұрын
Most definately something I could see myself using in one of my projects I have.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Excellent!
@pawel89pawel
@pawel89pawel 2 жыл бұрын
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 😂😂😂.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I'm glad it came in time.
@emon1019
@emon1019 3 ай бұрын
As always, good stuff. Thanks Tim
@IAmTimCorey
@IAmTimCorey 3 ай бұрын
You are welcome.
@bipinchandrakant3085
@bipinchandrakant3085 2 жыл бұрын
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.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@AmirAliZargaran82
@AmirAliZargaran82 2 ай бұрын
thank you very much for this excellent and clear intro
@IAmTimCorey
@IAmTimCorey 2 ай бұрын
You are welcome.
@AliMustafa-xp8ih
@AliMustafa-xp8ih 9 ай бұрын
Thank you very much Tim for every thing you are sharing with us , Keep up PLEASE
@IAmTimCorey
@IAmTimCorey 9 ай бұрын
You are welcome.
@someonesoumya
@someonesoumya Жыл бұрын
Thanks TIm , It's a Crystal clear.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome. I am glad it was helpful.
@TrevorNewsome
@TrevorNewsome 2 жыл бұрын
I wasn't aware of the Microsoft caching extension. Thank you and good advice.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@Kazem_Javadi
@Kazem_Javadi 2 жыл бұрын
Thank you Tim Corey 😊🙏🏻 This video was very good 👍🏻
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are most welcome. Thanks for watching.
@teriyakov
@teriyakov Жыл бұрын
That was shockingly easy to implement. Thanks as always. Keep up the great work.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@mohinikadasi5737
@mohinikadasi5737 Жыл бұрын
Nice video. Thanks for detail explanation.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@dasfahrer8187
@dasfahrer8187 2 жыл бұрын
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 🤣🤣🤣
@DanFlakes
@DanFlakes 2 жыл бұрын
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)
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Yep, that's true.
@jesusdelarua5995
@jesusdelarua5995 2 жыл бұрын
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 2 жыл бұрын
Not in the short term, but that is something I am considering.
@billyarredondopucp
@billyarredondopucp Жыл бұрын
Hi, Tim! It was an excellent explanation; thank you so much!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You're very welcome!
@krishj8011
@krishj8011 19 күн бұрын
Excellent Tutorial...
@IAmTimCorey
@IAmTimCorey 19 күн бұрын
Thank you!
@MayankSharma-qb6hc
@MayankSharma-qb6hc 2 жыл бұрын
Thank you Tim for this wonderful video it was really very helpful.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@lifeisgameplayit
@lifeisgameplayit 2 жыл бұрын
Yet another awesome tutorial from Tim . ; ]
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@jeremyvonhatten5811
@jeremyvonhatten5811 2 жыл бұрын
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 2 жыл бұрын
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 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.
@luizyoung226
@luizyoung226 2 жыл бұрын
Great lesson, Tim! Thanks again.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@erosnemesis
@erosnemesis Жыл бұрын
Using tryget would be the preferred way. Much cleaner too.
@ThePholosopher
@ThePholosopher Жыл бұрын
so helpful, Tim, thank you!!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@monkeycrunch9324
@monkeycrunch9324 7 ай бұрын
Humbly, thank you. :)
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
You are welcome.
@monkeycrunch9324
@monkeycrunch9324 6 ай бұрын
@IAmTimCorey hey, mr Corey.. I am a South African that cannot afford your full courses... How's about a give away video? Hmmm 😁😁
@RussianBananan
@RussianBananan 2 жыл бұрын
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.
@stefano_schmidt
@stefano_schmidt Жыл бұрын
have you found out how to achieve that?)
@ro2207
@ro2207 2 жыл бұрын
Hi Tim, great Video. Do you actually have a video about adding dependency injection into a desktop application?
@fieryscorpion
@fieryscorpion 2 жыл бұрын
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.
@aganeto1
@aganeto1 5 ай бұрын
Why we are transient for DataAccess DI, if all of them would see the same data? Why not singleton too ?
@hari2633
@hari2633 2 жыл бұрын
Very nice and good explanation..
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thank you!
@fbodirector7464
@fbodirector7464 2 жыл бұрын
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
@_rachid
@_rachid 4 ай бұрын
Thank you!
@IAmTimCorey
@IAmTimCorey 4 ай бұрын
You are welcome.
@tosinakinyemi3948
@tosinakinyemi3948 2 жыл бұрын
Thank you Tim.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@johnotu5610
@johnotu5610 2 жыл бұрын
Many Thanks, Tim !
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome!
@worldinstyle
@worldinstyle Жыл бұрын
Oh wow, how I missed ur tutorials. Thank you so much for this. A question: is memorycache thread safe?
@IAmTimCorey
@IAmTimCorey Жыл бұрын
Yes, it is thread safe.
@yanaraldaghestani6305
@yanaraldaghestani6305 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 2 жыл бұрын
locks? Can't think of anything else
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
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 2 жыл бұрын
@@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.
@LoverOf_Knowledge
@LoverOf_Knowledge 8 ай бұрын
Good job
@IAmTimCorey
@IAmTimCorey 8 ай бұрын
Thank you!
@AMurr-zm4wh
@AMurr-zm4wh 2 жыл бұрын
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.
@programmer5855
@programmer5855 2 жыл бұрын
15:00 for Memory Caching
@MuhammadIshaqkhan-jy8gp
@MuhammadIshaqkhan-jy8gp Жыл бұрын
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?
@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.
@DutchDJSteel
@DutchDJSteel 2 жыл бұрын
Couldn't you use a singleton for the SampleDataAccess?
@AS-kw1ob
@AS-kw1ob 2 жыл бұрын
Do you use another Mic? Quality was better before. Thanks for the vid.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Different room and I’m still working through the best setup.
@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.
@TheSjoerd
@TheSjoerd 2 жыл бұрын
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.
@286432531
@286432531 2 жыл бұрын
Hi Tim. I love watching your videos. Do you have any video talking about lazy loading ef database model set up ?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I don't. I don't really cover EF, except for one video.
@maneeshpardeshi4032
@maneeshpardeshi4032 2 жыл бұрын
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 жыл бұрын
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.
@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: kzfaq.infosearch?query=async
@abdulnaveed4984
@abdulnaveed4984 2 жыл бұрын
@@IAmTimCorey thank you sir for response
@vicenzovendetta3443
@vicenzovendetta3443 2 жыл бұрын
Wait, your new .NET 6 project already started with the usings without messing with the project file? How do I do that?
@messiah6670
@messiah6670 6 ай бұрын
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 6 ай бұрын
Here you go: kzfaq.info/get/bejne/o9Wida6i2dfRo6M.html
@messiah6670
@messiah6670 6 ай бұрын
@@IAmTimCorey thank you again 🙏
@petropzqi
@petropzqi 2 жыл бұрын
Great video
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@michaelshaw9997
@michaelshaw9997 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
@@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.
@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.
@memsom
@memsom 2 жыл бұрын
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 2 жыл бұрын
It is C# in general. I talked at the end about how you would use it in a desktop app.
@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 жыл бұрын
Yep. You will just need to manage your cache invalidation periods so you don't cause an issue.
@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?
@kostasgkoutis8534
@kostasgkoutis8534 2 жыл бұрын
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 2 жыл бұрын
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.
@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?
@VantazeVibesWorld
@VantazeVibesWorld 2 жыл бұрын
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 2 жыл бұрын
Watch the Suggestion Site App course here on KZfaq. We will be using in-memory caching in the app.
@VantazeVibesWorld
@VantazeVibesWorld 2 жыл бұрын
@@IAmTimCorey Ok got it. Thanks
@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?
@izikon1978
@izikon1978 2 жыл бұрын
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 2 жыл бұрын
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.
@girornsveinsson7970
@girornsveinsson7970 2 жыл бұрын
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 2 жыл бұрын
Memory pressure. If your memory pressure gets too high, you can flush the cache. That's not as easy with a singleton.
@jhanifkara8552
@jhanifkara8552 2 жыл бұрын
Hi can Imemorycaching be used in webassmbly?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I believe so. Just remember that you are storing it on the client's machine so it will be client-specific.
@jeremyleff
@jeremyleff 2 жыл бұрын
What are the advantages of using this over say the Azure Redis service?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
In memory is quick and for small jobs. Redis is for when those small jobs get larger.
@legittaco4440
@legittaco4440 2 жыл бұрын
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 2 жыл бұрын
On the server unless you are running Blazor WebAssembly, which runs on the client's machine.
@olgakhomyakova4760
@olgakhomyakova4760 2 жыл бұрын
Is this subject included in your new mastercourse update?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
No, this is outside the scope of the C# Mastercourse.
@adityarane2758
@adityarane2758 2 жыл бұрын
Can you please make some videos on xamarin mobile app development or apache cordova ?
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
I will add it to the list. Thanks for the suggestion.
@esmail9189
@esmail9189 2 жыл бұрын
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 2 жыл бұрын
Sure, just set the cache in that event and it will overwrite the current list.
@esmail9189
@esmail9189 2 жыл бұрын
@@IAmTimCorey Thank you so much
@govindagrawal3325
@govindagrawal3325 2 жыл бұрын
How can I make it thread safe??
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
The cache is thread-safe.
@nadervaghari51
@nadervaghari51 2 жыл бұрын
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 2 жыл бұрын
> 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 2 жыл бұрын
@@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 2 жыл бұрын
@@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 2 жыл бұрын
@@AMurr-zm4wh but the main question was can we use Singleton fields in place of In Memory Cache or not?
@AMurr-zm4wh
@AMurr-zm4wh 2 жыл бұрын
@@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?
@cw6692
@cw6692 2 жыл бұрын
Sound is awful. I started to watch and had to switch off.
@bobclemens8065
@bobclemens8065 2 жыл бұрын
You can always turn on CC in KZfaq
@DDDD-rr6uo
@DDDD-rr6uo 7 ай бұрын
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 7 ай бұрын
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.
Intro to Redis in C# - Caching Made Easy
1:27:29
IAmTimCorey
Рет қаралды 176 М.
10 C# Libraries To Save You Time And Energy
33:59
IAmTimCorey
Рет қаралды 206 М.
managed to catch #tiktok
00:16
Анастасия Тарасова
Рет қаралды 46 МЛН
Whoa
01:00
Justin Flom
Рет қаралды 24 МЛН
Cute kitty gadgets 💛
00:24
TheSoul Music Family
Рет қаралды 12 МЛН
If Barbie came to life! 💝
00:37
Meow-some! Reacts
Рет қаралды 76 МЛН
Writing C# without allocating ANY memory
19:36
Nick Chapsas
Рет қаралды 147 М.
Brutally honest advice for new .NET Web Developers
7:19
Ed Andersen
Рет қаралды 153 М.
The Only .NET Scheduler You Should Be Using!
16:38
Nick Chapsas
Рет қаралды 49 М.
Intro to Unit Testing in C# using XUnit
1:42:09
IAmTimCorey
Рет қаралды 413 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 354 М.
.NET 6 - Web API Caching with Redis ⏲🌐
1:04:23
Mohamad Lawand
Рет қаралды 35 М.
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 149 М.
Diagnosing memory leaks in .NET apps
37:32
dotnet
Рет қаралды 34 М.
managed to catch #tiktok
00:16
Анастасия Тарасова
Рет қаралды 46 МЛН