Тёмный

Making Your APIs Blazingly Fast in .NET 8! 

Nick Chapsas
Подписаться 311 тыс.
Просмотров 70 тыс.
50% 1

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

 

22 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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.
@pablocom
@pablocom Год назад
I love to see your passion explaining those things, ty for sharing
@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
@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”?
@eduarddumitru1
@eduarddumitru1 Год назад
In Copenhagen we cache the weather output for no more than 10 seconds 🤣
@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.
@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!
@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)?
@Jachtann
@Jachtann 8 месяцев назад
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.
@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.
@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?
@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
@ДмитрийФролов-э3ю
@ДмитрийФролов-э3ю 2 месяца назад
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.
@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.😂
@99MrX99
@99MrX99 Год назад
Can you invalidate for a specific entry? Like only invalidate for the London weather?
@josda1000
@josda1000 6 месяцев назад
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 3 месяца назад
@@josda1000if update our data table caching show the old one ??
@hamadanjum4720
@hamadanjum4720 Год назад
Waited so long for this. Greate job.
@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.
@baranacikgoz
@baranacikgoz Год назад
I remember your video implementing redis along with output cache yourself, microsoft listenned you ;;))
@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?
@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
@jerryjeremy4038
@jerryjeremy4038 5 месяцев назад
What if I want to use MS SQL? Is there a nuget package for that?
@ajkkarthik9049
@ajkkarthik9049 9 месяцев назад
can we add specific redis db based on language culture instead of 0 by default like i need 0 for english 1 for spanish ?
@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
@crackdesign
@crackdesign 11 месяцев назад
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.
@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
@urzaaaaa
@urzaaaaa Год назад
I was hoping you will show us the distributed part :)
@griffin123griffin
@griffin123griffin Год назад
he did ? Redis is the distributed cache
@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😂
@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.
@NikolaiKononov
@NikolaiKononov Год назад
What console extension do you use?
@blackenedsprite8542
@blackenedsprite8542 Год назад
Will this be updated in the API course?
@Kingside88
@Kingside88 Год назад
I do not using it but just wonder if this could useful for translations for example.
@seesharp81321
@seesharp81321 Год назад
Dude lives in GB and dares to ask 'how much can the weather change in 5 minutes?'! Brilliant! 😂
@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
@manchastyle
@manchastyle Год назад
Which IDE are you using ?
@robvaughan6649
@robvaughan6649 Год назад
JetBrains Rider.
@nztzn
@nztzn 9 месяцев назад
JetBrains Rider
@ВладиславДараган-ш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ф
@@kasperstergaard1592 well, it's not that bad, even YT or Twitter does this. It depends on nature of the data
@isnotnull
@isnotnull Год назад
Really COOL!
@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.
@lizard450
@lizard450 11 месяцев назад
lol I wrote this years ago... oh well guess i'll trash it now haha
@richardpayne
@richardpayne Год назад
The weather doesn't change in 5 minutes? I thought you lived in the UK, so you should know better. :D
@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
@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
Просмотров 113 тыс.
The NEW caching you should be using in .NET 7
18:17
Просмотров 77 тыс.
Forget Controllers and Minimal APIs in .NET!
14:07
Просмотров 72 тыс.
Brutally honest advice for new .NET Web Developers
7:19
The Pattern You MUST Learn in .NET
20:48
Просмотров 89 тыс.
The New Way of Parsing ANY Type in .NET
13:03
Просмотров 70 тыс.
The Magical Pattern to Organize .NET Minimal APIs
9:06
The New .NET 9 HybridCache That You Must Upgrade To!
14:34
Microservices are Technical Debt
31:59
Просмотров 553 тыс.