You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ConfigurationBuilderCacheHandlePart.WithExpiration throws the error "If expiration mode is not set to 'None', timeout cannot be zero." when ExpirationMode.Default is provided with a timeout of TimeSpan.Zero.
Severity: Low
Use Case
Writing an abstraction layer for application-specific caching which uses CacheManager underneath. Code using abstraction layer can optionally specify the ExpirationMode, which is then passed to the CacheFactory settings. By default ExpriationMode is configured to ExpirationMode.Default and Timeout is configured to TimeSpan.Zero.
Reproduction Code
varexpirationMode=ExpirationMode.Default;vartimeout=TimeSpan.Zero;varcacheManager=CacheFactory.Build<string>(cacheName,
s =>s.WithJsonSerializer().WithMicrosoftMemoryCacheHandle(cacheName).WithExpiration(expirationMode,timeout));
Expected Results
cacheManager is set to a non-null value, configured for Json serialization, MicrosoftMemoryCacheHandler, and an ExpirationMode of None (as Default is equivalent to None per src/CacheManager.Core/ExpirationMode.cs#L11).
Actual Results
InvalidOperationException thrown with message of "If expiration mode is not set to 'None', timeout cannot be zero.".
Recommended Fix
Update src/CacheManager.Core/Configuration/ConfigurationBuilder.cs#L496 to
ConfigurationBuilderCacheHandlePart.WithExpiration throws the error "If expiration mode is not set to 'None', timeout cannot be zero." when ExpirationMode.Default is provided with a timeout of TimeSpan.Zero.
Severity: Low
Use Case
Writing an abstraction layer for application-specific caching which uses CacheManager underneath. Code using abstraction layer can optionally specify the ExpirationMode, which is then passed to the CacheFactory settings. By default ExpriationMode is configured to ExpirationMode.Default and Timeout is configured to TimeSpan.Zero.
Reproduction Code
Expected Results
cacheManager is set to a non-null value, configured for Json serialization, MicrosoftMemoryCacheHandler, and an ExpirationMode of None (as Default is equivalent to None per src/CacheManager.Core/ExpirationMode.cs#L11).
Actual Results
InvalidOperationException thrown with message of "If expiration mode is not set to 'None', timeout cannot be zero.".
Recommended Fix
Update src/CacheManager.Core/Configuration/ConfigurationBuilder.cs#L496 to
Alternative Fix
Remove ExpirationMode.Default as a valid value, which would be a breaking change.
Work Around
Use ExpirationMode.None as default value if default value for ExpirationMode is needed.
The text was updated successfully, but these errors were encountered: