I love how concise your videos are, and that they're devoid of ego, unlike some other (purple) channels on these topics. Question: is it safe to assume that returning a cache hit will interrupt the pipeline? In other words, you didn't call "next()" during a cache hit. Does that mean that caching must always come last in the pipeline? Or is there a way to implement this such that validation or whatever can come afterward?
Thank you ! I’m glad you like the videos! To answer your question, yes, in the example all other pipelines after the cache will be short circuited and not executed.
I am somewhat uncomfortable about calling the Request an ICacheable. Isn't it the response that is cached and not the request? Maybe IGetCachedResponse?
Where would you typically run cache invalidation with mediatr? You could implement a similar approach using a pipeline, but often time you need more information than what's provided in the command. Eg. you may cache a single item by Id, but then that item may also exist in another request which returns a collection, which is cached by a different key.
There is a couple of different options. You could have your command implement an Invalidatable interface and use a behaviour similar to the caching. However, I think the better approach would be using domain events which are handled using mediatR event publishing. Then you can inject other services into your handler to perform all the logic you need. I might cover this in the future video 👍
Hi, nice video, just what I needed. An adjustment to your code would be to check for success or failure before caching - something like this: if (response is IResult typedResponse) if (typedResponse.IsSuccess)
Thanks for your great video. What is your solution for add handler to keep added item in cache? Is it good idea for command Handler to add item in database and cache(if not exist) to achieve better performance?
Which video has the validation behavior? Btw. great video, tho is it always the client's job to send query id or we can somehow hash the request on server to determin whether or not we encountered same request in the past?
Still currently editing that one at the moment, so hopefully will be out soon. Also, we are using the id sent by the client to cache the query. So in the example I sent Get todo by ID request using 1, it added the response to the cache. And then I sent the same get todo by ID request and instead of going to the request handler, it just got the response out of the cache.
Jump straight into the code here: 00:46 ✌
Looking forward for part 5. Really love this series :)
simple, short, and clear = awesome tutorials
Thanks for the great feedback!
Thanks a lot Jono for the awesome video.
I hope you talk about Cache Invalidation using MediatR Behavior too
Good work mate ...loving it !
Thank you! Appreciate the positive feedback 👍
I love how concise your videos are, and that they're devoid of ego, unlike some other (purple) channels on these topics.
Question: is it safe to assume that returning a cache hit will interrupt the pipeline? In other words, you didn't call "next()" during a cache hit. Does that mean that caching must always come last in the pipeline? Or is there a way to implement this such that validation or whatever can come afterward?
Thank you ! I’m glad you like the videos! To answer your question, yes, in the example all other pipelines after the cache will be short circuited and not executed.
Very nice video hope that you do series about clean architecture with CQRS
Thanks ! Glad you liked the video! I will add it to my backlog!
I am somewhat uncomfortable about calling the Request an ICacheable. Isn't it the response that is cached and not the request? Maybe IGetCachedResponse?
Where would you typically run cache invalidation with mediatr? You could implement a similar approach using a pipeline, but often time you need more information than what's provided in the command. Eg. you may cache a single item by Id, but then that item may also exist in another request which returns a collection, which is cached by a different key.
There is a couple of different options. You could have your command implement an Invalidatable interface and use a behaviour similar to the caching. However, I think the better approach would be using domain events which are handled using mediatR event publishing. Then you can inject other services into your handler to perform all the logic you need. I might cover this in the future video 👍
Hi, nice video, just what I needed.
An adjustment to your code would be to check for success or failure before caching - something like this:
if (response is IResult typedResponse)
if (typedResponse.IsSuccess)
_memoryCache.Set("yourkey", response);
Thanks for the positive feedback! And thanks for the suggestion! I appreciate it
Kaish!!!
Thanks for your great video. What is your solution for add handler to keep added item in cache? Is it good idea for command Handler to add item in database and cache(if not exist) to achieve better performance?
solid video.. subscribed!
Please continue posting dotnet content!
edit: Went into the repo to look at the code and I could only view the test folder?
How do you cache a query that has no parameter? Such as a query that returns a list but whose underlying method doesn't take parameters.
If you're still looking for an answer to this, the CacheKey would just be a constant.
Clean and clear! Can I implement a Redis Cache the same way as Memory Cache?
Thank you ! Yeah you can. Just replace memory cache with redis 👍
Which video has the validation behavior? Btw. great video, tho is it always the client's job to send query id or we can somehow hash the request on server to determin whether or not we encountered same request in the past?
Still currently editing that one at the moment, so hopefully will be out soon. Also, we are using the id sent by the client to cache the query. So in the example I sent Get todo by ID request using 1, it added the response to the cache. And then I sent the same get todo by ID request and instead of going to the request handler, it just got the response out of the cache.
@@jonowilliams26 thanks, now I get it!
Hi, your tutorial really helped me, could you do a video about testing MediatR commands and queries? Thank you.
Why just not using 'MemoryCache.Default' since it's found in 'System.Runtime.Caching''? Based on your example it would provide the same functionality.
Great but how to invalidate ? Without that this is incomplete. I'd be happy to see that
add Thread.Sleep(1000* 30) in get people method to appreciate the cache :D
please use this. for instance members, methods, etc. But the video is good.
Great video, thanks. But why do you say cache funny? It's pronounced kash
Thank you so much for all these videos. You should publish some courses on Udemy or pluralsight.com. I love your straight to the point tutorials.