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:
If no one expiration property is set into the DistributedCacheEntryOptions object, an infinite lifetime should be returned
If a null DistributedCacheEntryOptions object parameter is passed, an infinite lifetime should be returned; a better approach is to ensure that this method is never called with a null options parameter
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.
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.