asp.net-core-mvcstackexchange.redisoutputcache

Redis as OutputCacheProvider in ASP.NET Core 3.1 MVC


I have an ASP.NET webforms based website, which I am converting to ASP.NET Core 3.1 MVC.

I had used Redis as my OutputCache provider for caching website pages. My web.config had the settings for the same in earlier website.

<caching xdt:Transform="Replace">
  <outputCache defaultProvider="rdstest">
    <providers>
      <add name="rdstest" type="Microsoft.Web.Redis.RedisOutputCacheProvider" host="rdstest............."
           accessKey="xxxxxx=" databaseId ="1" port="xxxx" ssl="true" applicationName="xxxx" />
    </providers>
  </outputCache>
</caching>

I have looked online as what is the best approach for using redis for the same purpose, but could not find any simple implementation.

Most of the articles were using redis as data caching and very few showed how to simply cache the output pages.

Any help on this will be appreciated.

Thanks.


Solution

  • There is no built-in output cache in ASP.Net Core currently. The closes you get is the Response Caching Middleware but it will only work with an internal memory cache which you can't swap out for something else.

    The ASP.NET Core team has recognized this though and there is an issue tracking this in the .NET 7-Candidate milestone so if we get an official one it will be at earliest a year from now.

    So if you want output caching with redis support right now you will have to build your own middleware to cache the response (and serve cached responses).