2

I am not sure how to troubleshoot it but I am trying to implement ASP.NET Output Cache via Redis Output cache provider.

We have Redis server (non-azure) set up and I can store cache for general usage. However, when I try to setup ASP.NET output cache, it doesn't seem to save anything to cache!

I have installed Microsoft.Web.RedisOutputCacheProvider via Nuget. Web.Config is set up with following:

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

The MVC controller is setup with OutputCache attribute:

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

When I check the Redis, I don't see any OutputCache being stored.

Am I missing something? Is there a way to debug why it is not storing anything in cache?

4
  • Check this out learn.microsoft.com/en-us/azure/azure-cache-for-redis/… , is cache PING command working from your web application ? Commented Mar 13, 2019 at 5:29
  • I should mention that neither app or the cache servers are on Azure. None are. Besides that, I am able to utilise Redis Cache using the normal caching method within the code. However, if I choose to use the OutputCacheProvider for Output caching, I doesn't store anything. Commented Mar 13, 2019 at 5:53
  • Can you try to change your web.config as per this post ? github.com/moonpyk/mvcdonutcaching/issues/35 Commented Mar 13, 2019 at 6:08
  • I've tried it with the extra parameter on type and it is still not working. No errors. Commented Mar 13, 2019 at 6:41

2 Answers 2

2

Ok this was really silly.

When you install RedisOutputCacheProvider via Nuget, you will get this small doco in your app/web.config:

<!-- 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]
          />

It indicates the default value for "ssl" would be false. However, reading through the code itself, it is actually defaulted to true.

So explicitly setting ssl to false have fixed it.

EDIT

Oh and I had to downgrade RedisOutputCacheProvider to 1.7.5.

3.0.1 didn't work at all for me.

Sign up to request clarification or add additional context in comments.

Comments

1

I have mine working on local host without the SSL setting. In production I require it, but on mine it is part of the connectionstring (that I was given by my Redis hosting service).

The reason it was not working and you had to downgrade RedisOutputCacheProvider to 1.7.5 is because you are using Exchange.Redis.Strongname.dll (version 1.2.6)

As per this issue, Redis no longer requires a strongname because the base version is now strong named. https://github.com/Azure/aspnet-redis-providers/issues/107

So to use RedisOutputCacheProvider v3.0.144 you need to uninstall Exchange.Redis.Strongname.dll (version 1.2.6) and install Exchange.Redis.dll (version 2.0.601) via Nuget

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.