ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.9k stars 97 forks source link

[FEATURE] ♾️ Handle Infinity #126

Closed jodydonetti closed 1 year ago

jodydonetti commented 1 year ago

Problem

Community member @suhrab kindly reported that when using TimeSpan.MaxValue as the Duration, an ArgumentOutOfRangeException is being thrown when instead it should have been handled.

This, in turn, made a pattern emerge with which for "never expiring cache entries" the common way to do it may be to just set the duration to TimeSpan.MaxValue.

This situation, although maybe not that frequent, should be better handled.

Solution

Setting the Duration to TimeSpan.MaxValue is a scenario that should be gracefully handled. Also, other similar edge case scenarios should be handled, like:

On top of this it would be nice to add to FusionCacheEntryOptions a couple of methods like SetDurationInfinite() and SetDistributedCacheDurationInfinite(). This would:

Additional context

Nitpicking corner: the "infinite duration" would be for all intent and purposes, practically infinite. Having said that it cannot be of course literally infinite, but instead will be DateTimeOffset.MaxValue which in turn is Dec 31st 9999. In the xml docs I'm putting something like this:

/// <summary>
/// Set the duration to be infinite, so it will never expire.
/// <strong>NOTE:</strong> the expiration will not be literally "infinite", but it will be set to <see cref="DateTimeOffset.MaxValue"/> which in turn is Dec 31st 9999 which, I mean, c'mon. If that time will come and you'll have some problems feel free to try and contact me :-)
/// </summary>

I know, but still better to specify that 😅.

jodydonetti commented 1 year ago

Hi all, I just release v0.20.0-preview2 🎉

Unless some problems will came up this week, the next weekend I'll release the final v0.20.0.

jodydonetti commented 1 year ago

Hi everyone, I've finally released the new v0.20.0 🎉