MichaCo / CacheManager

CacheManager is an open source caching abstraction layer for .NET written in C#. It supports various cache providers and implements many advanced features.
http://cachemanager.michaco.net
Apache License 2.0
2.35k stars 456 forks source link

Outputcache issues #164

Closed hermesramos closed 7 years ago

hermesramos commented 7 years ago

Hello. First of all, thank you for this fantastic product, it is amazing.

If you dont mind, I would like to report some bugs using outputcache.

Here is my config:

  <cacheManager xmlns="http://cachemanager.michaco.net/schemas/CacheManagerCfg.xsd">
    <managers>
       <cache name="defaultCache" updateMode="Up" enableStatistics="false" enablePerformanceCounters="false" backplaneName="redis1" backplaneType="CacheManager.Redis.RedisCacheBackplane, CacheManager.StackExchange.Redis" serializerType="CacheManager.Serialization.Json.GzJsonCacheSerializer,CacheManager.Serialization.Json">
        <handle name="systemRuntime" ref="systemRuntimeHandle" />
        <handle name="redis1" ref="redisHandle" isBackplaneSource="true" />
      </cache>  
    </managers>
    <cacheHandles>
      <handleDef id="systemRuntimeHandle" type="CacheManager.SystemRuntimeCaching.MemoryCacheHandle`1, CacheManager.SystemRuntimeCaching" />
      <handleDef id="redisHandle" type="CacheManager.Redis.RedisCacheHandle`1, CacheManager.StackExchange.Redis" />
    </cacheHandles>
  </cacheManager>
  <outputCache defaultProvider="CacheManagerOutputCacheProvider">
    <providers>
      <add cacheName="defaultCache" name="CacheManagerOutputCacheProvider" type="CacheManager.Web.CacheManagerOutputCacheProvider, CacheManager.Web" />
    </providers>
  </outputCache>
<cacheManager.Redis xmlns="http://cachemanager.michaco.net/schemas/RedisCfg.xsd" xdt:Transform="Insert">
    <connections>
      <connection id="redis1" allowAdmin="true" password="password" ssl="true">
        <endpoints>
          <endpoint host="url" port="6380" />
        </endpoints>
      </connection>
    </connections>
  </cacheManager.Redis>

Here are the bugs:

1. When using serializer CacheManager.Serialization.Json.GzJsonCacheSerializer with outputcache, it generates the following exception:

Unable to find a constructor to use for type System.Web.Caching.CachedVary. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path '', line 1, position 2.

The exception is raised after retrieval (it adds to the redis cache fine)

2. When setting outputcache duration to 0 (not expires), cachemanager/redis thinks it is 0 seconds and it is doesnt work (is already expired)

3. Outputcache is being created with 2 keys on redis. For example:

"a2/pagename" "a2/pagenameHQFCDE"

The first one never expires (-1) and the second on works fine. I dont know why it creates 2 keys. I think it should create only one with the correct ttl.

4. When using CacheManager.StackExchange.Redis 1.1.0 with the CacheManager.Web I get the following exception (When using CacheManager.StackExchange.Redis 1.0.1 it works fine. I dont know why):

Parser Error Message: Version string portion was too short or too long. Source Error:

<outputCache defaultProvider="CacheManagerOutputCacheProvider">
<providers>
<add cacheName="defaultCache" name="CacheManagerOutputCacheProvider" type="CacheManager.Web.CacheManagerOutputCacheProvider, CacheManager.Web" />
</providers>
</outputCache>

Thanks for all the help. Please let me know if you have additional questions, I will try to answer to my best knowledge.

MichaCo commented 7 years ago

Hi @hermesramos, thanks for reporting all this although I think not all of those are actually bugs ;)

Regarding 1) - Serialization Unfortunately, the output cache stuff has a few limitations as almost everything in System.Web.Caching is internal. The serialization is pretty restricted because of that and as far as I have tested, only binary serialization doesn't care and works.

So, regarding setting the serialization, don't use Json or GzJson or anything else than default (binary serialization).

Regarding 2) If I set duration to zero, nothing gets cached (as expected) => [OutputCache(Location = OutputCacheLocation.Server, Duration = 0)]

Setting duration to zero means it should not cache at all. You have to give it a positive number in seconds to actually cache things (that's how OutputCache works and has nothing to do with CacheManager).

Regarding 3) That key without expiration is added by the ASP.NET framework. It is not your page data, just some meta information I think. So, just don't worry about that one, that's again just how OutputCache works and has nothing to do with CacheManager

Regarding 4) Yup, that's actually a bug. If nothing is specified, the configuration section sets the version string to string.Empty which causes that issue, I'll fix it. Until then you can work around by setting the version to a valid value if you want, strictCompatibilityModeVersion="3.0" for example I have added a new issue to track it => #165 as this one is more a discussion.

hermesramos commented 7 years ago

Hello! Good morning and thanks for the prompt answer.

All looks good. You are right on the duration 0!

MichaCo commented 7 years ago

Ok cool, I'll close this one then