Тёмный

Intro to In-Memory Caching in C# 

IAmTimCorey
Подписаться 421 тыс.
Просмотров 80 тыс.
50% 1

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...

Опубликовано:

 

28 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 170   
@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
@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.
@Kazem_Javadi
@Kazem_Javadi 2 года назад
Thank you Tim Corey 😊🙏🏻 This video was very good 👍🏻
@IAmTimCorey
@IAmTimCorey 2 года назад
You are most welcome. Thanks for watching.
@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.
@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?)
@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?
@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.
@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: ru-vid.comsearch?query=async
@abdulnaveed4984
@abdulnaveed4984 2 года назад
@@IAmTimCorey thank you sir for response
@messiah6670
@messiah6670 7 месяцев назад
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 7 месяцев назад
Here you go: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-morBKqtqmso.html
@messiah6670
@messiah6670 7 месяцев назад
@@IAmTimCorey thank you again 🙏
@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.
@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.
@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.
@lastonedown
@lastonedown 2 года назад
Best tutorial I have found for caching. Great work Tim and keep the videos coming.
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@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.
@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.
@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.
@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
@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.
@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 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.
@aganeto1
@aganeto1 6 месяцев назад
Why we are transient for DataAccess DI, if all of them would see the same data? Why not singleton too ?
@ДенисМалахов-к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!
@ro2207
@ro2207 2 года назад
Hi Tim, great Video. Do you actually have a video about adding dependency injection into a desktop application?
@erosnemesis
@erosnemesis Год назад
Using tryget would be the preferred way. Much cleaner too.
@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.
@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.
@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.
@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.
@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.
@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.
@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?
@CRBarchager
@CRBarchager 2 года назад
Most definately something I could see myself using in one of my projects I have.
@IAmTimCorey
@IAmTimCorey 2 года назад
Excellent!
@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.
@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?
@AmirAliZargaran82
@AmirAliZargaran82 3 месяца назад
thank you very much for this excellent and clear intro
@IAmTimCorey
@IAmTimCorey 3 месяца назад
You are welcome.
@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.
@emon1019
@emon1019 4 месяца назад
As always, good stuff. Thanks Tim
@IAmTimCorey
@IAmTimCorey 4 месяца назад
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 🤣🤣🤣
@DutchDJSteel
@DutchDJSteel 2 года назад
Couldn't you use a singleton for the SampleDataAccess?
@programmer5855
@programmer5855 2 года назад
15:00 for Memory Caching
@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.
@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.
@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.
@ThePholosopher
@ThePholosopher Год назад
so helpful, Tim, thank you!!
@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.
@someonesoumya
@someonesoumya Год назад
Thanks TIm , It's a Crystal clear.
@IAmTimCorey
@IAmTimCorey Год назад
You are welcome. I am glad it was helpful.
@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.
@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!
@krishj8011
@krishj8011 Месяц назад
Excellent Tutorial...
@IAmTimCorey
@IAmTimCorey Месяц назад
Thank you!
@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.
@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.
@AliMustafa-xp8ih
@AliMustafa-xp8ih 10 месяцев назад
Thank you very much Tim for every thing you are sharing with us , Keep up PLEASE
@IAmTimCorey
@IAmTimCorey 10 месяцев назад
You are welcome.
@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 RU-vid. We will be using in-memory caching in the app.
@VantazeVibesWorld
@VantazeVibesWorld 2 года назад
@@IAmTimCorey Ok got it. Thanks
@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.
@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.
@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.
@TrevorNewsome
@TrevorNewsome 2 года назад
I wasn't aware of the Microsoft caching extension. Thank you and good advice.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@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.
@DDDD-rr6uo
@DDDD-rr6uo 8 месяцев назад
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 8 месяцев назад
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.
@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.
@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.
@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.
@MayankSharma-qb6hc
@MayankSharma-qb6hc 2 года назад
Thank you Tim for this wonderful video it was really very helpful.
@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.
@_rachid
@_rachid 5 месяцев назад
Thank you!
@IAmTimCorey
@IAmTimCorey 5 месяцев назад
You are welcome.
@billyarredondopucp
@billyarredondopucp Год назад
Hi, Tim! It was an excellent explanation; thank you so much!
@IAmTimCorey
@IAmTimCorey Год назад
You're very welcome!
@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.
@monkeycrunch9324
@monkeycrunch9324 8 месяцев назад
Humbly, thank you. :)
@IAmTimCorey
@IAmTimCorey 8 месяцев назад
You are welcome.
@monkeycrunch9324
@monkeycrunch9324 8 месяцев назад
@IAmTimCorey hey, mr Corey.. I am a South African that cannot afford your full courses... How's about a give away video? Hmmm 😁😁
@LoverOf_Knowledge
@LoverOf_Knowledge 9 месяцев назад
Good job
@IAmTimCorey
@IAmTimCorey 9 месяцев назад
Thank you!
@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.
@mohinikadasi5737
@mohinikadasi5737 2 года назад
Nice video. Thanks for detail explanation.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@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
@lifeisgameplayit
@lifeisgameplayit 2 года назад
Yet another awesome tutorial from Tim . ; ]
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@hari2633
@hari2633 2 года назад
Very nice and good explanation..
@IAmTimCorey
@IAmTimCorey 2 года назад
Thank you!
@govindagrawal3325
@govindagrawal3325 2 года назад
How can I make it thread safe??
@IAmTimCorey
@IAmTimCorey 2 года назад
The cache is thread-safe.
@ldiniz_x
@ldiniz_x 2 года назад
Great lesson, Tim! Thanks again.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@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?
@tosinakinyemi3948
@tosinakinyemi3948 2 года назад
Thank you Tim.
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome.
@petropzqi
@petropzqi 2 года назад
Great video
@IAmTimCorey
@IAmTimCorey 2 года назад
Thanks!
@johnotu5610
@johnotu5610 2 года назад
Many Thanks, Tim !
@IAmTimCorey
@IAmTimCorey 2 года назад
You are welcome!
@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 RU-vid
Далее
Intro to Redis in C# - Caching Made Easy
1:27:29
Просмотров 177 тыс.
Шоколадная девочка
00:23
Просмотров 84 тыс.
"Когти льва" Анатолий МАЛЕЦ
53:01
Writing C# without allocating ANY memory
19:36
Просмотров 149 тыс.
Intro to Unit Testing in C# using XUnit
1:42:09
Просмотров 416 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 360 тыс.
Factory Pattern in C# with Dependency Injection
1:07:33
Просмотров 107 тыс.
Stackalloc and Spans
30:17
Просмотров 10 тыс.
Caching in ASP.NET C# - Memory Caching is AMAZING
12:24
Realtime Chat App in React Native and AWS (Backend) 🔴
3:29:01
C# Async Await Mistakes | Part 1
10:19
Просмотров 35 тыс.
You are doing .NET logging wrong. Let's fix it
25:29
Просмотров 173 тыс.