Skip to content

REQUEST - Caching

Our caching provider is built on top of Microsoft.Extensions.Caching.Memory Caching is insanely easy with request handlers in Shiny Mediator.

  1. Install Shiny.Mediator.Caching to your project.

  2. On your request handler (result based), add [Cache] attribute to the handler.

    public class MyHandler : IRequestHandler<MyRequest, MyResult>
    public async Task<MyResult> Handle(MyRequest request, CancellationToken ct)
    return new MyResult();
  3. In your host startup, with the AddShinyMediator call, add the following:

    services.AddShinyMediator(x => x..AddMemoryCaching(y =>
    y.ExpirationScanFrequency = TimeSpan.FromSeconds(5);

There are many additional properties you can use to interact with the cache setup

public class CacheAttribute : Attribute
public CacheItemPriority Priority { get; set; } = CacheItemPriority.Normal;
public int AbsoluteExpirationSeconds { get; set; }
public int SlidingExpirationSeconds { get; set; }