cnblogs / EnyimMemcachedCore

.NET Memcached client. Available on https://www.nuget.org/packages/EnyimMemcachedCore
Apache License 2.0
162 stars 45 forks source link

Impossible to indicate a infinite lifetime (no expiration) for a cache entry #225

Open Hybos opened 6 months ago

Hybos commented 6 months ago

DistributedCacheEntryOptions throws an ArgumentOutOfRangeException when SlidingExpiration is tried to be set to 0 (TimesSpan.Zero or TimeSpan.FromSeconds(0)).

As there is no way to do that, the alternative is to use either null options parameter or a DistributedCacheEntryOptions object without any expiration property set, when Set methods are invoked.

When a null options parameter is passed to Set methods, a NullReferenceException is thrown.

When an instance of DistributedCacheEntryOptions without any expiration property set is passed as options parameter, an ArgumentException is thrown into the GetExpiration method (private uint GetExpiration(DistributedCacheEntryOptions options)).

Therefore it is not possible to indicate an infinite lifetime for a cache entry, no using any Set method from the client class nor any Set method from the extension methods. All alternatives have been tried for all combinations with the methods Set, SetAsync, SetSting and SetStringAsync.

In any case, GetExpiration method from MemcachedClient should consider:

I would also take a look to Set and SetAsync methods, at least, from the MemcachedClient class, since only when SlidingExpiration property into the DistributedCacheEntryOptions is set, a sliding expiration key is added. Either I'm misunderstanding the logic or this code smells.