Making Your APIs Blazingly Fast in .NET 8!

  Рет қаралды 70,607

Nick Chapsas

Nick Chapsas

Күн бұрын

Пікірлер: 92
@jamestyrer451
@jamestyrer451 Жыл бұрын
I have a crow that now says "Hello everybody, i'm Nick". Thanks for all the videos love your channel.
@mightygingercles6481
@mightygingercles6481 Жыл бұрын
I was very confused how this differentiated from the ResponseCache middleware. Maybe I missed it during your video, but I found the answer in the MS docs for Response Cache: "Is typically not beneficial for UI apps such as Razor Pages because browsers generally set request headers that prevent caching. Output caching, which is available in ASP.NET Core 7.0 and later, benefits UI apps. With output caching, configuration decides what should be cached independently of HTTP headers."
@LrgamezD
@LrgamezD Жыл бұрын
Amazing video. Now that I'm working with Docker I just realize how easy it makes development without the need of installing 3rd party sotfware. Obsessed with container technology now
@michaszura8940
@michaszura8940 Жыл бұрын
Agree. I was amazed with Docker and it's possibilities, when it comes to additional software or, for instance, integration tests.
@TkrZ
@TkrZ Жыл бұрын
I know you could probably create a custom policy for it, but it'd be nice if there was an easier way (e.g. a fluent method call) to specify what types of response to cache. For example I'd like to cache Ok responses for the city "London" for 5 minutes, but cache the NotFound responses for the city "asdf123" for several hours or days.
@alimctavish998
@alimctavish998 Жыл бұрын
This Is What I Do I Sit On You! , Sit On You! , Sit On You!....
@kijanawoodard
@kijanawoodard Жыл бұрын
Good video. Side note, the full redis-stack image (omit -server on the end of the image name) also runs Redis Insight in case someone doesn't have Another Redis Desktop Manager.
@sriramancs1119
@sriramancs1119 Жыл бұрын
Hey Nick. Thanks for the video. Here you are using a simple location string as parameter. How about complex object as parameter? Will the caching work correctly, as the object may differ on every api call?
@DamianLesiuk
@DamianLesiuk Жыл бұрын
It don't. You can't even invalidate by param name. It always invalidates everything.
@gileee
@gileee Жыл бұрын
Caching is actually a very difficult problem as soon as the complexity of your API increases even a little bit. Like what about caching endpoints that return lists, what about objects with different keys that can be used for fetching (I guess just duplicate the cache entries per query right), what if those endpoints return an object with lazy loaded fields? I look at caching more as a necessary evil to be used sparingly when absolutely all else fails.
@chrismantonuk
@chrismantonuk Жыл бұрын
Perfect timing! Thanks 🙏 I was just looking at a high latency request today which would benefit from some caching. Question: can you invalidate certain keys? For example if you wanted to fetch fresh weather for London but not Milan, can you use tagging to say “I want to invalidate the cache for ?city=London but keep ?city=Milan”?
@pablocom
@pablocom Жыл бұрын
I love to see your passion explaining those things, ty for sharing
@eduarddumitru1
@eduarddumitru1 Жыл бұрын
In Copenhagen we cache the weather output for no more than 10 seconds 🤣
@crackdesign
@crackdesign Жыл бұрын
For those like me scratching their heads why output caching doesn't work with authenticated endpoints: you'll need to either redefine base policy or write your custom one.
@microtech2448
@microtech2448 Жыл бұрын
Hey, thanks for the video. Can you please explain how to create own sample service with certain options just like any other services we use in startup and configure their options?
@samuelschwager
@samuelschwager Жыл бұрын
there are 3 things in computer science that are hard: 1) cache invalidation 2) off by one errors
@phizc
@phizc Жыл бұрын
Forgot naming things. And scope creep.😂
@kamushekdev
@kamushekdev Жыл бұрын
As someone who lives in Saint-Petersburg I can say that the weather could change several times within 5 minutes XDXD
@1dfe-4e68-bd9f
@1dfe-4e68-bd9f Жыл бұрын
the same in Almaty😂
@user-ti5ce4hg1o
@user-ti5ce4hg1o Жыл бұрын
when the cache expires, and you get 100 calls at that endpoint at the same time, will they all go in trying to get data (i.e., requires you to thread lock the access to the data refresh call) or redis has a built-in option to control that access? (i.e., only one call goes in to refresh the data and the remaining 99 wait for the cached data after the first call gets served). And if redis has such multi-threaded control option built-in, is it scalable or only per instance?
@LeMustache
@LeMustache Жыл бұрын
It seems that by default locking is enabled which should prevent the issue you're describing
@griffin123griffin
@griffin123griffin Жыл бұрын
it is specifically designed for that
@baranacikgoz
@baranacikgoz Жыл бұрын
I remember your video implementing redis along with output cache yourself, microsoft listenned you ;;))
@zoltanzorgo
@zoltanzorgo Жыл бұрын
As this is intended to facilitate scaling up, and the key used looks to contain the port number as well - this can result in different keys for each instance of the service depending on the infrastructure. I am wondering how can that be excluded? And in general: how can I format the key that is created?
@cicpolk
@cicpolk Жыл бұрын
Exactly my concern too. With the approach in video, service instances will not share the cache keys at all.
@99MrX99
@99MrX99 Жыл бұрын
Can you invalidate for a specific entry? Like only invalidate for the London weather?
@josda1000
@josda1000 7 ай бұрын
Each call is per city in this case, so yes. It depends on how the API's request parameters are set up. A cache entry is recorded per api method and parameter set.
@3in1ceylon
@3in1ceylon 4 ай бұрын
@@josda1000if update our data table caching show the old one ??
@ДмитрийФролов-э3ю
@ДмитрийФролов-э3ю 3 ай бұрын
One tiny problem - it does NOT cache authenticated requests, and it's by design. All this beauty and you can't actually use this with API, because most of the time it is protected with API keys :/ No, you still can use the OutputCache, but you have to rewrite original policy code, because devs don't want to implement a toggle in configuration method.
@Velociapcior
@Velociapcior Жыл бұрын
Hey Nick I use output cache in my application, but I would like to have option to invalidate cache by some dynamic value. For example when user with specific id is updated, I would like to evict his entry from cache. With this approach you evicted all 'weather' tagged entries. What if we would like to evict only Milan and leave London in cache? This issue stops me from putting output cache in my whole applicaiton. Is it worth of follow up video?
@DaminGamerMC
@DaminGamerMC Жыл бұрын
Instead of using this minimal API approach you want to use the service with dependency injection and cache it by UUID for example. Use the service like he did invalidation.
@Velociapcior
@Velociapcior Жыл бұрын
@@DaminGamerMC I am not using minimal APIs at all. Currently there is no out of the box functionality to invalidate specific entries in this Output cache functionality that I am aware of. IOutputCacheStore has only EvictByTag method. And with tags defined as in the video, you are not able to evict single entry. Only all of entries related to this tag
@EikeSchwass
@EikeSchwass Жыл бұрын
@@Velociapcior couldn't you just use a different tag for every entry (i.e. the key/id of the user)? Then when you want to invalidate a user, just evictbytag(userId)?
@Velociapcior
@Velociapcior Жыл бұрын
@@EikeSchwass how would you like to do that in attribute?
@diaaway
@diaaway Жыл бұрын
Would love to have an out of box solution for this!
@MrIsrael3000
@MrIsrael3000 Жыл бұрын
Nice feature, How nice could be doing caching from the httpclient? To avoid call the API, is it anything like that?
@mackie1001
@mackie1001 Жыл бұрын
A Redis IDistributedCache implementation would be your friend here
@Masteroxify
@Masteroxify Жыл бұрын
The problem with caching is to determine how long we can store cached value. In case of token it is cool because if token would become obsolete then we get error. In case of weather we could return wrong data.
@mattiaricci910
@mattiaricci910 Жыл бұрын
Is it possibile to evict by key? For example if the weather for London gets updated (let's pretend that it's my API that's updating the weather), could I just delete the cache entry for that specific key (maybe using the query string)?
@canergurelsoy6875
@canergurelsoy6875 Жыл бұрын
This is a nice one, but I'M just wondering where you gat .NET 8 RC1?
@DamianLesiuk
@DamianLesiuk Жыл бұрын
It also works with net 7.
@juliangzr4998
@juliangzr4998 Жыл бұрын
Great vídeo Nick. I wonder if it works along with Authorization. Once i tried ourput caching in .NET 6 with authorized controllers and it didn't work. It would be great to have the opportunity to vary by Authorization header
@OALBERTO
@OALBERTO Жыл бұрын
Hey Nick, have you thought of creating a subscription model for dometrain? I’ve take courses from you in the past and I’m wondering if this is something we could expect in a near future now that you are inviting external experts
@insteor
@insteor Жыл бұрын
hi there. could you please share your experience with completed course? if you don't mind to share what courses you have taken and how useful found them. thanks in advance!
@OALBERTO
@OALBERTO Жыл бұрын
I've taken the Minimal API one. It was very helpful at the time because Nick covered the topic in depth.@@insteor
@urzaaaaa
@urzaaaaa Жыл бұрын
I was hoping you will show us the distributed part :)
@griffin123griffin
@griffin123griffin Жыл бұрын
he did ? Redis is the distributed cache
@Jachtann
@Jachtann 9 ай бұрын
Trying to implement redis cache right now, because api that I'm creating is being deployed into k8s. I did it little different and experiencing timeouts when testing with thousands of requests at once. I believe its somehow thread related? Like threads are waiting to be completed? I will definettely try this way you showed in video, to see if I'll experience same problem. If anybody have some experience with this problem, or just have any ideas, please, let me know.
@matiascasag
@matiascasag Жыл бұрын
What if you want to return the cached data ordered in a different way? How would you do it?
@dvdrelin
@dvdrelin Жыл бұрын
it is an output cache and depends on request. if request has an instruction of ordering as parameter (e.g. in query string such as ..&order=desc&...), the cache middleware will scan for such key. And if not found the mapped delegate will be called and the result will be stored with key that accounts this parameter. there are two ways - or cache each ordered response (the same tag will help on evicting) or cache unordered and then order on the client side.
@dvdrelin
@dvdrelin Жыл бұрын
also you may decouple fetching and presentation of data, cache just data that fetched from storage by predicate and prepare it to present from api doing necessary ordering always.
@hamadanjum4720
@hamadanjum4720 Жыл бұрын
Waited so long for this. Greate job.
@jerremm
@jerremm Жыл бұрын
If multiple requests come in before the first one is returned, so the rest still call the weatherservice or do they wait for the first one to finish?
@porcinetdu6944
@porcinetdu6944 Жыл бұрын
What happened if multiple people hit the endpoint at the same moment when it is not cache anymore ? Because the http call is long may it be possible that there is multiple people entering the controller and so make multiple http call ?
@exemory
@exemory Жыл бұрын
Same question
@NikolaiKononov
@NikolaiKononov Жыл бұрын
What console extension do you use?
@ajkkarthik9049
@ajkkarthik9049 10 ай бұрын
can we add specific redis db based on language culture instead of 0 by default like i need 0 for english 1 for spanish ?
@jerryjeremy4038
@jerryjeremy4038 6 ай бұрын
What if I want to use MS SQL? Is there a nuget package for that?
@blackenedsprite8542
@blackenedsprite8542 Жыл бұрын
Will this be updated in the API course?
@seesharp81321
@seesharp81321 Жыл бұрын
Dude lives in GB and dares to ask 'how much can the weather change in 5 minutes?'! Brilliant! 😂
@Kingside88
@Kingside88 Жыл бұрын
I do not using it but just wonder if this could useful for translations for example.
@manchastyle
@manchastyle Жыл бұрын
Which IDE are you using ?
@robvaughan6649
@robvaughan6649 Жыл бұрын
JetBrains Rider.
@nztzn
@nztzn 10 ай бұрын
JetBrains Rider
@maksymlazorenko7636
@maksymlazorenko7636 Жыл бұрын
Hi Nick, but what about Multitenant application ? Does it persist per (token?)
@nickchapsas
@nickchapsas Жыл бұрын
You can customise it yes
@maksymlazorenko7636
@maksymlazorenko7636 Жыл бұрын
@@nickchapsas thanks :)
@ourjamie
@ourjamie Жыл бұрын
Now that is useful
@ВладиславДараган-ш3ф
@ВладиславДараган-ш3ф Жыл бұрын
I don't get the idea of distributed cache since such data as in example can be easily cached in memory to avoid additional network call + cache DB overhead Today memory is fairly cheap and caching of small sets of data in external system looks redundant
@kasperstergaard1592
@kasperstergaard1592 Жыл бұрын
Because you might run multiple instances of your service for scalability. If you cache in memory they'll each end up with different caches and give inconsistent responses. I memory is the right answer if you only have one instance. It's the wrong answer if you have more.
@TkrZ
@TkrZ Жыл бұрын
If you have more than one instance of your application running behind a load balancer, with in-memory caching the work will be need to be ran on each instance for it to be cached locally to that instance. If you use a distributed cache only one of the instances needs to perform the work.
@ВладиславДараган-ш3ф
@ВладиславДараган-ш3ф Жыл бұрын
@@kasperstergaard1592 well, it's not that bad, even YT or Twitter does this. It depends on nature of the data
@isnotnull
@isnotnull Жыл бұрын
Really COOL!
@lizard450
@lizard450 Жыл бұрын
lol I wrote this years ago... oh well guess i'll trash it now haha
@ProfessorCodemunkie
@ProfessorCodemunkie Жыл бұрын
I've never been a fan of caching results at the endpoint level. What happens if you want to use your Weather service in another endpoint? Each one would be caching different values whereas if your cache logic was in the service it would be available for any consumer.
@JansthcirlU
@JansthcirlU Жыл бұрын
your API key is visible in the video, just so you know
@reikooters
@reikooters Жыл бұрын
In older videos he's said "don't bother trying to use it cause it will be invalid by the time I release the video" and I think he stopped bothering to say that now
@nickchapsas
@nickchapsas Жыл бұрын
Yeah they are always invalidated after shooting
@mariocamspam72
@mariocamspam72 Жыл бұрын
​@@nickchapsasHey, at least you get extra engagement from these types of comments
@JansthcirlU
@JansthcirlU Жыл бұрын
@@reikooters ah I see, thanks
@JansthcirlU
@JansthcirlU Жыл бұрын
@@nickchapsas thanks for clarifying!
@IcaroFelix2023
@IcaroFelix2023 Жыл бұрын
That looks a good approach to keep sensitive data of users from authorization module, better than use browser's localstorage or session storage.
@elan2199
@elan2199 Жыл бұрын
I don't think it makes sense
@richardpayne
@richardpayne Жыл бұрын
The weather doesn't change in 5 minutes? I thought you lived in the UK, so you should know better. :D
@psyckojoe
@psyckojoe Жыл бұрын
œ
@RaVq91
@RaVq91 Жыл бұрын
.NET8 has nothing to do with redis. Thumb down for that click bait.
Background Tasks Are Finally Fixed in .NET 8
10:29
Nick Chapsas
Рет қаралды 116 М.
What's New in .NET 9 with Examples
25:02
Nick Chapsas
Рет қаралды 40 М.
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 96 МЛН
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 203 МЛН
Why .NET's memory cache is kinda flawed
14:13
Nick Chapsas
Рет қаралды 56 М.
Goodbye controllers, hello Minimal APIs - Nick Chapsas - NDC London 2023
54:28
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 83 М.
167. Should I Create A Minimal API Or Full API?
7:40
IAmTimCorey
Рет қаралды 39 М.
Don't Use Polly in .NET Directly. Use this instead!
14:58
Nick Chapsas
Рет қаралды 71 М.
Build Clean Messaging in .NET with MassTransit
21:44
Nick Chapsas
Рет қаралды 102 М.
How To Design Amazing REST APIs
18:57
Amichai Mantinband
Рет қаралды 18 М.
Fix Your Controllers By Refactoring To Minimal APIs
14:56
Milan Jovanović
Рет қаралды 44 М.
.NET Containers advancements in .NET 8 | .NET Conf 2023
25:38
The New .NET 9 HybridCache That You Must Upgrade To!
14:34
Nick Chapsas
Рет қаралды 54 М.
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 96 МЛН