Intro to In-Memory Caching in C#

  Рет қаралды 81,258

IAmTimCorey

IAmTimCorey

Күн бұрын

Пікірлер: 170
@jankool01
@jankool01 2 жыл бұрын
I like these short videos with simple and complete examples.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@lastonedown
@lastonedown 2 жыл бұрын
Best tutorial I have found for caching. Great work Tim and keep the videos coming.
@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.
@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.
@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.
@ДенисМалахов-к9э
@ДенисМалахов-к9э 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.
@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.
@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
@emon1019
@emon1019 6 ай бұрын
As always, good stuff. Thanks Tim
@IAmTimCorey
@IAmTimCorey 6 ай бұрын
You are welcome.
@AliMustafa-xp8ih
@AliMustafa-xp8ih Жыл бұрын
Thank you very much Tim for every thing you are sharing with us , Keep up PLEASE
@IAmTimCorey
@IAmTimCorey Жыл бұрын
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.
@TrevorNewsome
@TrevorNewsome 2 жыл бұрын
I wasn't aware of the Microsoft caching extension. Thank you and good advice.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@teriyakov
@teriyakov Жыл бұрын
That was shockingly easy to implement. Thanks as always. Keep up the great work.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome.
@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.
@lifeisgameplayit
@lifeisgameplayit 2 жыл бұрын
Yet another awesome tutorial from Tim . ; ]
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@AmirAliZargaran82
@AmirAliZargaran82 5 ай бұрын
thank you very much for this excellent and clear intro
@IAmTimCorey
@IAmTimCorey 5 ай бұрын
You are welcome.
@ThePholosopher
@ThePholosopher 2 жыл бұрын
so helpful, Tim, thank you!!
@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.
@someonesoumya
@someonesoumya Жыл бұрын
Thanks TIm , It's a Crystal clear.
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You are welcome. I am glad it was helpful.
@billyarredondopucp
@billyarredondopucp Жыл бұрын
Hi, Tim! It was an excellent explanation; thank you so much!
@IAmTimCorey
@IAmTimCorey Жыл бұрын
You're very welcome!
@CRBarchager
@CRBarchager 2 жыл бұрын
Most definately something I could see myself using in one of my projects I have.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Excellent!
@mohinikadasi5737
@mohinikadasi5737 2 жыл бұрын
Nice video. Thanks for detail explanation.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@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.
@ldiniz_x
@ldiniz_x 2 жыл бұрын
Great lesson, Tim! Thanks again.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@MayankSharma-qb6hc
@MayankSharma-qb6hc 2 жыл бұрын
Thank you Tim for this wonderful video it was really very helpful.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@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.
@hari2633
@hari2633 2 жыл бұрын
Very nice and good explanation..
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thank you!
@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.
@krishj8011
@krishj8011 3 ай бұрын
Excellent Tutorial...
@IAmTimCorey
@IAmTimCorey 3 ай бұрын
Thank you!
@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.
@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 🤣🤣🤣
@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
@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.
@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?
@johnotu5610
@johnotu5610 2 жыл бұрын
Many Thanks, Tim !
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome!
@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.
@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.
@monkeycrunch9324
@monkeycrunch9324 10 ай бұрын
Humbly, thank you. :)
@IAmTimCorey
@IAmTimCorey 10 ай бұрын
You are welcome.
@monkeycrunch9324
@monkeycrunch9324 10 ай бұрын
@IAmTimCorey hey, mr Corey.. I am a South African that cannot afford your full courses... How's about a give away video? Hmmm 😁😁
@messiah6670
@messiah6670 9 ай бұрын
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 9 ай бұрын
Here you go: kzbin.info/www/bejne/o6DVc36nqdagqdE
@messiah6670
@messiah6670 9 ай бұрын
@@IAmTimCorey thank you again 🙏
@tosinakinyemi3948
@tosinakinyemi3948 2 жыл бұрын
Thank you Tim.
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
You are welcome.
@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.
@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: kzbin.infosearch?query=async
@abdulnaveed4984
@abdulnaveed4984 2 жыл бұрын
@@IAmTimCorey thank you sir for response
@aganeto1
@aganeto1 8 ай бұрын
Why we are transient for DataAccess DI, if all of them would see the same data? Why not singleton too ?
@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?
@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.
@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 KZbin. We will be using in-memory caching in the app.
@VantazeVibesWorld
@VantazeVibesWorld 2 жыл бұрын
@@IAmTimCorey Ok got it. Thanks
@DutchDJSteel
@DutchDJSteel 2 жыл бұрын
Couldn't you use a singleton for the SampleDataAccess?
@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.
@RANVEER.4321
@RANVEER.4321 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.
@LoverOf_Knowledge
@LoverOf_Knowledge 11 ай бұрын
Good job
@IAmTimCorey
@IAmTimCorey 11 ай бұрын
Thank you!
@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.
@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 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.
@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.
@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 Жыл бұрын
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.
@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!
@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.
@petropzqi
@petropzqi 2 жыл бұрын
Great video
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
Thanks!
@_rachid
@_rachid 7 ай бұрын
Thank you!
@IAmTimCorey
@IAmTimCorey 7 ай бұрын
You are welcome.
@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.
@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.
@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.
@erosnemesis
@erosnemesis 2 жыл бұрын
Using tryget would be the preferred way. Much cleaner too.
@programmer5855
@programmer5855 2 жыл бұрын
15:00 for Memory Caching
@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.
@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.
@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?
@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.
@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.
@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.
@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
@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.
@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?
@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.
@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.
@govindagrawal3325
@govindagrawal3325 2 жыл бұрын
How can I make it thread safe??
@IAmTimCorey
@IAmTimCorey 2 жыл бұрын
The cache is thread-safe.
@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 KZbin
@DDDD-rr6uo
@DDDD-rr6uo 10 ай бұрын
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 10 ай бұрын
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
Рет қаралды 180 М.
Why .NET's memory cache is kinda flawed
14:13
Nick Chapsas
Рет қаралды 56 М.
Thank you Santa
00:13
Nadir Show
Рет қаралды 51 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 42 МЛН
小路飞和小丑也太帅了#家庭#搞笑 #funny #小丑 #cosplay
00:13
家庭搞笑日记
Рет қаралды 10 МЛН
Implementing In-Memory Caching in ASP.NET Core Applications
16:58
Cache Systems Every Developer Should Know
5:48
ByteByteGo
Рет қаралды 519 М.
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 86 М.
Caching in ASP.NET C# - Memory Caching is AMAZING
12:24
tutorialsEU - C#
Рет қаралды 25 М.
Stackalloc and Spans
30:17
Coding Tutorials
Рет қаралды 11 М.
The Only .NET Scheduler You Should Be Using!
16:38
Nick Chapsas
Рет қаралды 56 М.
You are doing .NET logging wrong. Let's fix it
25:29
Nick Chapsas
Рет қаралды 174 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 973 М.