【问题标题】:Redis as OutputCacheProvider in ASP.NET Core 3.1 MVCRedis 作为 ASP.NET Core 3.1 MVC 中的 OutputCacheProvider
【发布时间】:2021-12-26 16:18:15
【问题描述】:

我有一个基于 ASP.NET Webforms 的网站,我正在将其转换为 ASP.NET Core 3.1 MVC。

我曾使用 Redis 作为我的 OutputCache 提供程序来缓存网站页面。我的web.config 在之前的网站上也有同样的设置。

<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>

我在网上查看了将 redis 用于相同目的的最佳方法,但找不到任何简单的实现。

大部分文章都使用 redis 作为数据缓存,很少有人展示如何简单地缓存输出页面。

我们将不胜感激。

谢谢。

【问题讨论】:

    标签: asp.net-core-mvc stackexchange.redis outputcache


    【解决方案1】:

    目前 ASP.Net Core 中没有内置的输出缓存。你得到的关闭是Response Caching Middleware,但它只适用于你不能换成其他东西的内部内存缓存。

    虽然 ASP.NET Core 团队已经认识到这一点,并且在 .NET 7-Candidate 里程碑中有一个 issue tracking this,所以如果我们得到一个正式的,它最早会在一年后。

    因此,如果您现在想要支持 redis 的输出缓存,则必须构建自己的中间件来缓存响应(并提供缓存的响应)。

    【讨论】:

    • 谢谢 Karl-Johan,难怪我一直在寻找一种更简单的方法来获得内置支持。
    猜你喜欢
    • 1970-01-01
    • 2020-06-18
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 2020-09-22
    • 2021-02-06
    • 2020-12-03
    • 1970-01-01
    相关资源
    最近更新 更多