gpt4 book ai didi

asp.net-mvc - Redis 的 ASP.NET 输出缓存提供程序不存储

转载 作者:可可西里 更新时间:2023-11-01 11:23:45 33 4
gpt4 key购买 nike

我不确定如何解决它,但我正在尝试通过 Redis 输出缓存提供程序实现 ASP.NET 输出缓存。

我们设置了 Redis 服务器(非 Azure),我可以存储缓存以供一般使用。但是,当我尝试设置 ASP.NET 输出缓存时,它似乎没有将任何内容保存到缓存中!

我已经通过 Nuget 安装了 Microsoft.Web.RedisOutputCacheProvider。Web.Config 设置如下:

<caching>
<outputCache defaultProvider="MyRedisOutputCache">
<providers>
<add name="MyRedisOutputCache" type="Microsoft.Web.Redis.RedisOutputCacheProvider" host="ServerName" port="6464" accessKey="PasswordToRedis" />
</providers>
</outputCache>
</caching>

MVC Controller 设置了 OutputCache 属性:

[OutputCache(Duration = 3600, VaryByParam = "*", Location = OutputCacheLocation.ServerAndClient)]
public JsonResult GetLookupData()

当我检查 Redis 时,我没有看到任何 OutputCache 被存储。

我错过了什么吗?有没有办法调试它为什么不在缓存中存储任何内容?

最佳答案

好吧,这真的很傻。

当你通过 Nuget 安装 RedisOutputCacheProvider 时,你将在你的 app/web.config 中得到这个小 doco:

<!-- For more details check https://github.com/Azure/aspnet-redis-providers/wiki --><!-- Either use 'connectionString' OR 'settingsClassName' and 'settingsMethodName' OR use 'host','port','accessKey','ssl','connectionTimeoutInMilliseconds' and 'operationTimeoutInMilliseconds'. --><!-- 'databaseId' and 'applicationName' can be used with both options. --><!--
<add name="MyRedisOutputCache"
host = "127.0.0.1" [String]
port = "" [number]
accessKey = "" [String]
ssl = "false" [true|false]
databaseId = "0" [number]
applicationName = "" [String]
connectionTimeoutInMilliseconds = "5000" [number]
operationTimeoutInMilliseconds = "1000" [number]
connectionString = "<Valid StackExchange.Redis connection string>" [String]
settingsClassName = "<Assembly qualified class name that contains settings method specified below. Which basically return 'connectionString' value>" [String]
settingsMethodName = "<Settings method should be defined in settingsClass. It should be public, static, does not take any parameters and should have a return type of 'String', which is basically 'connectionString' value.>" [String]
loggingClassName = "<Assembly qualified class name that contains logging method specified below>" [String]
loggingMethodName = "<Logging method should be defined in loggingClass. It should be public, static, does not take any parameters and should have a return type of System.IO.TextWriter.>" [String]
redisSerializerType = "<Assembly qualified class name that implements Microsoft.Web.Redis.ISerializer>" [String]
/>

它表示“ssl”的默认值为 false。但是,仔细阅读代码本身,它实际上默认为 true

因此将 ssl 显式设置为 false 已修复它。

编辑

哦,我不得不将 RedisOutputCacheProvider 降级到 1.7.5。

3.0.1 对我来说根本不起作用。

关于asp.net-mvc - Redis 的 ASP.NET 输出缓存提供程序不存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55134886/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com