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.33k stars 458 forks source link

Understanding what it means to set an expiration in a multi layer scenario.... #291

Closed natiki closed 4 years ago

natiki commented 4 years ago

Hi,

So I have the following basic configuration with an in memory with 30 second expiry and Redis with 5 minute expiry.

<cacheHandles>
      <handleDef id="SystemRuntimeHandle" type="CacheManager.SystemRuntimeCaching.MemoryCacheHandle`1, CacheManager.SystemRuntimeCaching" defaultExpirationMode="Absolute" defaultTimeout="30s" />
      <handleDef  id="redisSliding" type="CacheManager.Redis.RedisCacheHandle`1, CacheManager.StackExchange.Redis" defaultExpirationMode="Sliding" defaultTimeout="5m" />
</cacheHandles>

So assuming I make a the following call:

_CacheManager.Expire("someKey",  ExpirationMode.Absolute, ExpirationMode.Absolute, new TimeSpan(1, 0, 0));

Does that ultimately mean I have only "changed" the layer 1 (in memory cache) to a one hour absolute expiration and the layer 2 Redis gets the default of 5 minutes? In other words is the only way to explicitly change the Redis expiry for the same item by using CacheHandles https://github.com/MichaCo/CacheManager/issues/190#issuecomment-329587387.

So in my case that would be something like:

_CacheManager.CacheHandles.Skip(1).Expire("someKey",  ExpirationMode.Absolute, ExpirationMode.Absolute, new TimeSpan(10, 0, 0));

if I wanted the Redis key to stay there absolute for 10 hours (as opposed to the default 5m sliding)?

MichaCo commented 4 years ago

The .Expire method should have documentation which says exactly what it does. If that's not clear enough let me know.

Could you also please use Stackoverflow for questions, Github issues are for bugs and issues and not for Q&A primarily ;) thanks

natiki commented 4 years ago

My apologies, the documentation is clear - not sure how I missed that because I must have read it a bunch of times. I will also move to SO for if it is clearly Q&A.