There are 2 hard problems in computer science: cache invalidation, naming things and off-by-1 errors.
@b4singularity2 жыл бұрын
😂
@jamesjohnmitchell2 жыл бұрын
There are 2 hard problems in computer science 0) Cache invalidation 1) Naming things 5) Async call backs 2) Off by one errors 3) Buffer overrun 4) Scope creep
@EdKolis Жыл бұрын
The -2 billion main weapons of the Spanish inquisition are surprise, fear, a fanatical devotion to the Pope, integer overflow errors...
@johncunningham19284 ай бұрын
thats actually 0011 problems
@LDdrums20Ай бұрын
So true
@Szwarcus152 жыл бұрын
Like learning from your videos. "Alexis Texas" made my day 🤣🤣
@theAutomaTom7 ай бұрын
I think she's more of a WCF gal, and less REST.
@siya.abc1232 жыл бұрын
The web is about to get a massive performance boost ! This is awesome
@Dustyy012 жыл бұрын
Just an amazing showcase in this short video. Very very helpful for many ppl🔥👍
@OldShoolGames2 жыл бұрын
Great video as always, thank you for your effort !
@greenwoodricky Жыл бұрын
Absolute legend. Just implemented caching and needed to evict by id and I was struggling to find anything anywhere.
@StuartHemming2 жыл бұрын
Would love to see how this new stuff works in conjunction with Redis
@gregcyrus27392 жыл бұрын
Very useful for search results.
@antonmartyniuk2 жыл бұрын
Fantastic feature. Will use it day 1 after release of .NET 7
@maciejgawe44072 жыл бұрын
Best .NET channel mate, short but full of info
@hassejansson Жыл бұрын
How can can we use/implement this in a service class?
@alexclark67772 жыл бұрын
Not sure if there's a way around this when defining policies, but it would be nice if there was a "non-blocking" solution to when the cache has an expired entry that's being requested by the client. I wrote a simple cache mechanism a while back which would return the "stale" object to the client while updating the cache in the background when it determined (triggered by a request) that the entry had outlived its expiration date. The vast majority of the time the client didn't care that it was getting something that was (for e.g.) 61 minutes old, especially if it meant a rapid response. Often times throughput is more important than rigidly adhering to the policy's TTL.
@Kingside882 жыл бұрын
Caching is great and I like the new feature. Also your'e presantation was great. But as always with caching: When the application grows and data became complex caching can open hard to maintain issues
@nickchapsas2 жыл бұрын
That’s part of the fun of solution architecture. I’ve solved these problems many times and I’m always having so much fun coming up with days to deal with cache eviction and efficient caching
@jerryjeremy40382 жыл бұрын
I really like your hacky methods
@EwanDobsonFan2 жыл бұрын
Very nice feature can’t wait to try this out
@avunda7032 жыл бұрын
Hey Nick, and thank you for all amazing content! Any plans on making a video on structs? When to use them, what pitfalls to avoid etc.
@nickchapsas2 жыл бұрын
Great video idea! Will add it in the backlog
@juanmiguel4312 жыл бұрын
Is it better having the IDs as guid or is it perfectly fine having them as integers ?
@sinoergin2 жыл бұрын
Great video dude. Also new caching system is look like powerful. Thanks for ur effort!
@sadaja252 жыл бұрын
Hi Nick, super awsome content, as usual :)
@sergiom.9542 жыл бұрын
Very useful, thanks for the video 👏👏
@expertdevs2 жыл бұрын
Great video as usual, keep it up
@20windfisch112 жыл бұрын
Is it also possible to use this cache in gRPC services?
@metaltyphoon2 жыл бұрын
Are Sick Chapnick and Chip Nacksas your bothers?
@nickchapsas2 жыл бұрын
It’s indeed a big family
@zhebed11952 жыл бұрын
If i will use classical controller will I be able to use this caching in .net 7 or it is only working in minimal apis?
@NiamorH2 жыл бұрын
he showed attributes so I guess there will be support for regular controllers
@harindaka2 жыл бұрын
Hey Nick. Apparently outputcache does not cache authenticated responses by default. The only solution I could find is to create a custom IOutputCachePolicy. Is there no way to get builder methods to make the base policy include/cache authenticated responses or a better way?
@jespereriksen2702 жыл бұрын
I'm dealing with this myself. And it seems that by adding a custom policy, i can't assign different policies to different endpoints. No matter how i tag / arrange the policies, i can only get the base policy to work.
@solero_2 жыл бұрын
You should do a course about creating production quality APIs
@nickchapsas2 жыл бұрын
There is something coming soon
@oksatoki2 жыл бұрын
@@nickchapsas please make it long enough and detailed if possible hahaha
@martinrj302 жыл бұрын
looking forward to the ETAG episode
@catalan28572 жыл бұрын
Hey Nick thanks so much for the awesome content! Could you tell which font you're using?
@sohampatel10632 жыл бұрын
It is Jetbrain mono
@catalan28572 жыл бұрын
@@sohampatel1063 No its not, compare by curly brackets
@baranacikgoz Жыл бұрын
Is there a way to use 'Tag' with Controllers?
@michaldivismusic2 жыл бұрын
Shout-out Alexis Texas 👍
@EdKolis Жыл бұрын
This looks really useful! Thanks for explaining it, it's not all that intuitive looking!
@mariomamalis2 жыл бұрын
This is great. One question I have: we cannot really use this in more complex endpoints that have paging sorting filtering etc that would make each request very dynamic right? This is perfect for usage in simple endpoints that return either all or one record from the database. Is that correct?
@MrRclemens2 жыл бұрын
Does the endpoint know which page the user requested? If so, you can use it as a caching variable
@ApolloJKD19732 жыл бұрын
@@MrRclemens good point. The problem is that the same page can return different data if the sorting and filtering is different. I guess you can create cache keys for each combo. Not sure of this could become problematic if there are thousands of permutations but I hear you.
@EdKolis Жыл бұрын
Couldn't the sorting at least be done in a different layer, or even client side?
@ApolloJKD1973 Жыл бұрын
@@EdKolis not if you wanna sort the entirety of the data
@stefangranath38412 жыл бұрын
Awesome stuff
@sohampatel10632 жыл бұрын
It looks like this feature is removed because i am now unable to find those methods but previously i was. Can you please confirm whether it it coming in .net 7 or not?
@zapeweb2 жыл бұрын
Hey, Nick! Another nice content. I'm new to caching and have a question (maybe a noob one): in a 3 layer solution (UI + BLL + DAL), where should I implemente the caching? At the UI or at the DAL? Regards!!
@nickchapsas2 жыл бұрын
You can have it at both for different reasons in each area. There isn’t a one size fits all solution. Generally UI layer caching will be the best performer because you don’t have to do any compute but it’s tricky especially with authentication and different users
@shioli39272 жыл бұрын
What he showed in the video would be between your UI and BLL usually. As in API response caching. You can do the same for frontends, mostly. Unless you are using blazor client or something like vue for the frontend then this type of caching is irrelevant, you´d just keep global state (which is also significantly simpler, because you don´t have to worry about different users and such with a client side UI solution). Personally, I´d prioritize caching at the API layer like he showed unless the data is too large and transfer time is what you are worried about more than compute time (which probably means you would not want to keep it in memory on your server anyways). Caching at the API layer gives you the benefits no matter what client is being used (even if the answer is no client and the user scripted his own).
@danielcarmona73862 жыл бұрын
Great video! One question prob I didn't understand, how was this done before? Something implicit? Would you mind helping me find old documentation? Thanks!
@nickchapsas2 жыл бұрын
It was a whole different feature. Check for “Response caching”
@sinamohammadzadeh1813 Жыл бұрын
Some of my requests are POST with some body parameters, How can I cache post methods and vary it by body parameters?
@pedroferreira92342 жыл бұрын
It's normal to use a combination of outputcache(distributed) and low level distributed cache right?
@nickchapsas2 жыл бұрын
Yea totally normal. Some requests might be tricky to output cache, for example complex authenticated requests, so having caching on your data layer for example is totally normal and in fact, a good practice
@Punkologist2 жыл бұрын
Hi, I have a question about this that I haven't really been able to find the answer to. I have an endpoint that gets notifications for a user with no params at all like : Unread() It uses the token/principal to see who the user is and called the backend with that. This is to make sure only the authenticated user can get their own data. So I can't really filter by params etc.. How would I use this to cache that result, but then if a new notification is added invalidate the cache just for that user? I kind of want to set a tag at run time based on the user? Then I can evict that tag on the insert endpoint as I will know which user's data is being inserted. Edit: nevermind I have figured it out using your custom policy example to set the tag based on the email claim :)
@neilsg20012 жыл бұрын
Maui or xaml or DDD please 🙏
@friendlyfox21892 жыл бұрын
when I log in, the output cache is ignored, is there any way I can output cache while a user is logged in?
@pilotboba2 жыл бұрын
I assume this uses in process memory. How does this affect container memory configuration? Also, with a scaled out backend is there support for some second-level cache like redis or whatever?
@nickchapsas2 жыл бұрын
Memory is relative to what you’re caching. If your responses are 50kb long then you can do the math based on the cache variations etc. yes this is extensible with Redis and there will be a dedicated video showing how to use it
@pilotboba2 жыл бұрын
@@nickchapsas Sure, I was curious if there was some upper limit which would automatically evict older cached items if there was memory pressure.
@stanislav72282 жыл бұрын
Hey Nick, thank you for the video! I have a small question about your example. In the POST handler, the service creates the customer, evicts the cache by tag, and you pass the cancellation token there (11:10). But what if the user cancels the request before the EvictByTagAsync method invokes, will it lead to the behavior when the customer was created but the cache is not evicted? Thank you very much!
@nickchapsas2 жыл бұрын
Technically it is possible but it is very unlikely because in a real app you would have some sort of event that is being published and then a service to consume it and evict the cache from Redis. This flow is just for demo purposes
@testcloud34042 жыл бұрын
And what when we have several app instances? Is there any way to tackle that?
@nickchapsas2 жыл бұрын
Yeap, you can use a distributed cache like Redis as the storage for the cache. It’s very easy and I will show it in a future video
@Anymn12 жыл бұрын
The problem I always run into with caching is when you are dealing with mutliple webservers. Caching goes fine, but it's rather complex to invalidate the caches on the other servers. Any ideas for that?
@nickchapsas2 жыл бұрын
Simply use a distributed datastore like Redis to store your cache data. There will be a video fairly soon showing how you can easily do that.
@maslennikovvaleriy2 жыл бұрын
Maybe we can use VaryByValue? We have HttpContext there, so we can vary by value of our route value. 12:06
@nickchapsas2 жыл бұрын
That will make the cache vary but it doesn’t give any context to the eviction method since you can’t pass a value from the vary method to the tag method
@florent9555 Жыл бұрын
You typically dont want to have an endpoint to return all the users. Imagine having 100k user, do you really want to return all of those? Could be quite memory intensive for the server that the webserver is running on. I usually have some kind of pagination by default for those kind of endpoints
@bipinchandrakant30852 жыл бұрын
Thanks for the awesome content. I tried to implement the similar approach in the Controller to set a tag but I don't see an option to set the Tag directly within the attribute. I created a new policy in options to set the tag name and bind the policy. WIth this I was able to evict the cache as expected. Is there an better way to set tag instead of creating a policy? [HttpGet] [OutputCache(Duration = 60, PolicyName = "AddUserTag")] public List Get() { return dataStore.Select(data => data.Value).ToList(); }
@bartoszpalmi5750 Жыл бұрын
I have the same problem. Did you found better solution?
@bipinchandrakant3085 Жыл бұрын
@@bartoszpalmi5750 No, I haven't found a better solution.
@benoit923202 жыл бұрын
When do you come in France?
@nickchapsas2 жыл бұрын
Are there any big .NET developer conferences in France?
@yitzchokneuhaus2 жыл бұрын
Hey nick. Is it possible to integrate this with MediatR and repository pattern? Or it must coupled with your controllers?
@nickchapsas2 жыл бұрын
This is more of an API Layer cache so by definition it should be coupled with your UI later, in your case the controllers
@mikaelsoderstrom24342 жыл бұрын
Great video! Is it possible to add "chained" tags in some way? Let's say that I have a list of users (UserGroup) and then I call DELETE /users/123 after which I would like to clear the cache for both "users" and "usergroups". I could of course make sure to do it manually, but is there anything built-in to clear both of them at the same time?
@nickchapsas2 жыл бұрын
Yeah the WithTag method accepts an array so you can have as many as you want
@022442 жыл бұрын
Hi! Can you make video about .NET MAUI?
@nickchapsas2 жыл бұрын
It’s not a topic that interests me so I won’t be covering it
@johnli78182 жыл бұрын
just wondering Output Caching is out at .Net1.0 based on their website. How is this Caching different to that one??why do you call it new? I like you video. this Cache can really help my project.
@johnli78182 жыл бұрын
btw, does this Output caching work with controller actions not the way you write it (not minimal API), would love to see another video about that.
@nickchapsas2 жыл бұрын
You’re looking at the very old .NET Framework output caching. You can still use the new output caching with controllers with attributes
@johnli78182 жыл бұрын
@@nickchapsas thanks for the reply. I can’t wait them to release the .Net7
@pagorbunov2 жыл бұрын
Who is Sick Chapnick?
@astralpowers2 жыл бұрын
Will this have a redis specific implementation that will allow you to delete all cached items by tags? There is no way to remove cache item by tags with IDistributedCache (which only has remove by id) and this makes cache invalidation painful.
@nickchapsas2 жыл бұрын
The Redis provider will be able to do this yes
@astralpowers2 жыл бұрын
@@nickchapsas Yeah, I just saw that there will be an IOutputCacheStore that does this invalidation. I hope this will support .NET 6 because it will be tough to convince my boss to use .NET 7, and I don't really want to implement this logic myself
@darkogele Жыл бұрын
How do i do this on controller based not minimapl api ?
@nickchapsas Жыл бұрын
Same setup but with attributes on the actions
@darkogele Жыл бұрын
@@nickchapsas For some reason is not working for me it keeps getting the data from the SQL.... but when i set it with the standard IMemoryCache is working fine.. anyway thank you for replaying Nick you are awesome :)
@xentricator2 жыл бұрын
Hello Nick. I'm interested in using this with Redis, but noticed that IResponseCache is synchronous. Is there not an async alternative?
@nickchapsas2 жыл бұрын
Response cache is different from output cache. I will be showing in a video soon how you can use Redis with this
@xentricator2 жыл бұрын
@@nickchapsas Thanks for the clarification, I obviously got mixed up. I should have been looking at IOutputCacheStore which you will probably be showing in your next video on this topic
@gbelkin42 жыл бұрын
Hi Nick, thanks for video. Question: all of that is in-memory cache, right? So, if i want to use some distributed cache (Redis) for set of microservices instances, this approach won't help me, right?
@apr0l2 жыл бұрын
5:24
@gbelkin42 жыл бұрын
@@apr0l oops, thanks
@vmachacek2 жыл бұрын
hello Nick, would you mind posting sample project to Github?
@nickchapsas2 жыл бұрын
The project is available on GitHub for my Patreons
@vmachacek2 жыл бұрын
@@nickchapsas is there also code you presented as part of Minimal API @ NDC recently? I'm very interested to see how you put it together
It's a shame query notifications aren't supported in Azure DB, and first class support for hooking .NET cache invalidation to them. It really is the perfect feature for it, but it's a pain to setup on a table by table basis end-to-end and locks you out of using Azure DB. App level cache invalidation falls apart as soon as you realize you've got other systems updating the same data. Ideally you'd have a data service that EVERYTHING absolutely must go through, but the reality is that in practice has limitations and performance issues for many use cases, and it's hard to get usage adopted universally throughout an organization. Query notifications solve alot of these problems because the database, where the common denominator is for updates, becomes the notifier of invalidations for the app level caches.
@urzaaaaa2 жыл бұрын
You cache like crazy and then IIS puts your Web app to sleep after 15 minutes :)
@nickchapsas2 жыл бұрын
I have never used IIS in my life
@chanwengkin31222 жыл бұрын
in case you r using IIS, you can actually set it to always running to that it does not terminate or suspend
@Syntax-Savvy2 жыл бұрын
IIS are the old days but you can also configurebit away.
@MegaSuperhund2 жыл бұрын
@@nickchapsas 😂😂😂😂
@Punkologist2 жыл бұрын
@@nickchapsas sadly some of us work in dinosaur companies lol. Although we are moving everything to Azure now.
@dimitris470 Жыл бұрын
Interesting, but somehow it bothers me in terms of separation of concerns. The framework kinda goes into the trap that so many others go, trying to be everything in a tightly coupled highly integrated bulk. In the era of containers, I'd rather setup a specialized proxy like varnish if my app really needs caching.
@nothingisreal63452 жыл бұрын
Now this video already demonstrated the new caching in .NET 7. But I didn't understand what has changed compared to .NET 6.
@nickchapsas2 жыл бұрын
It’s completely new. It’s not a change. It’s a new type of caching all together
@6stringmonk2 жыл бұрын
As Nick says in the video, the existing cache tries to implement caching as per the spec and that can cause your cache to be bypassed in many common situations. For example, when a user hits F5 in chrome, it sends a Cache-Control: max-age=0; header and the caching middleware will not serve the request from cache. It looks like this new cache will behave more like you'd expect if want application output caching. If anyone is curious, there is a messy workaround for the old cache. You can strip the cache-control header from incoming requests before it hits the cache middleware. I had to learn about this the hard way ;).
@seannewell3972 жыл бұрын
Css or JavaScript paths? What you smokin. That's in my CDN not my API.
@nickchapsas2 жыл бұрын
You mean gateway/reverse proxy. CDN is for static files. It can be but it doesn’t have to be. As explained in the video this is application level caching centralised in a distributed cache like Redis, with application specific rules. Nothing to do with gateway level caching
@bosegeorge14252 жыл бұрын
Nick it will be great if you can upload courses to udemy.
@nickchapsas2 жыл бұрын
Unfortunately it wouldn’t be great for me since I would be losing money if I did that
@haterealm2 жыл бұрын
Woohoo, Microsoft reinvented OutputCacheAttribute, that was around MVC 3.
@davidfowl2 жыл бұрын
Software goes in cycles
@emmepombar33282 жыл бұрын
This is all good until you have multiple APIs running in a cloud. When API 1 updates a dataset A that is cached in API 2, you have a problem.
@nickchapsas2 жыл бұрын
I made a follow up video on how to use Redis when apps are scaled out
@hassejansson2 жыл бұрын
I noticed a huge error in your data, you've entered the wrong birth year for Alexis, her birtday year is in 1985.. ;)
@ZaahidAdams2 жыл бұрын
Shoutout to Alexis Texas
@LindenMikus2 жыл бұрын
possible to use this on console app as well?
@k3daevin2 жыл бұрын
Sure
@gordonfreimann2 жыл бұрын
Alexis Texas 😂😂😂
@nickchapsas2 жыл бұрын
Finally a man of culture
@01mrsir2 жыл бұрын
pagination??
@nickchapsas2 жыл бұрын
You can cache based on page number and page size and invalidate the cache as shown
@maskettaman14882 жыл бұрын
What? What about it?
@theAutomaTom7 ай бұрын
I don't believe that "opt-out by header value" works, man.
@umer.on.youtube Жыл бұрын
STOP USING THIS FOOLISH IDE. USE VS CODE OR VS
@berkanbilgin22878 ай бұрын
Dude… for the love of the God…. You speak sooo fast and with that accent it really makes it so hard to understand.. remember you are making tutorials.. its like “bla bla bla bla bla” and you move so fast.. please consider these feedbacks for better outcomes. Thanks for the video