Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

14 Comments

  1. A great article and excellent idea.

    How would you go about updating / refreshing the cache. I.e. say you add a new customer and you want to trigger any update before the cache expires.

    A couple of ways to do this could be:
    1) Set a new property RefreshCache, that will force the cache to be updated
    2) Use the existing BypassCache property to update the cache, while it returns the non cached version

    Thoughts?

  2. Could you briefly tell us which is best or what the difference is between Lazy caching (in Blazor Hero) and Response Caching with MediatR (in this Article)?

  3. Hi Mukesh,
    Want to know what is popularity of Blazor in the software development market.
    Does it will pick up as Angular in near future.

  4. Thanks Mukesh! This is a great article and it will help me replace the multiple CacheRepositories per API in the service with this generic Mediatr pipeline behavior.

    Just wondering that where is the configuration for distributed Redis connection string is specified or where the connection is made to Redis host.

  5. This pattern and idea causes caching operations to be performed on all queries and commands.
    Well in commands that this is not necessary. So how to prevent this? Also do not store information in the cache.

  6. I have followed this blog. My caching works. However `SlidingExpiration` is null in the request parameter log. Is this normal?

  7. In v10 of mediatr, the cachingbehavior is causing a compile error. Any ideas?

    The type ‘TRequest’ cannot be used as type parameter ‘TRequest’ in the generic type or method ‘IPipelineBehavior’. There is no boxing conversion or type parameter conversion from ‘TRequest’ to ‘MediatR.IRequest’.

    1. You’ve to provide the TResponse unboxing, this way:

      public class CachingBehavior
      : IPipelineBehavior
      where TRequest : ICacheableMediatrQuery
      {}

      public interface ICacheableMediatrQuery : IRequest {}

  8. HI Mukesh,
    when i try to run below code in cachingbehaviour

    var resp = (Encoding.Default.GetString(cachedResponse).ToResult().ValueOrDefault);
    response = JsonConvert.DeserializeObject (resp);
    return response;
    response is not deserialised and returns issucess=true only and count =0

    1. I solved it like that;

      Encoding.Default.GetBytes(JsonConvert.SerializeObject(response,new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects }));