Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConfigurationBuilderCacheHandlePart.WithExpiration throws error when ExpirationMode.Default given #192

Closed
brandondahler opened this issue Sep 21, 2017 · 2 comments
Labels
Milestone

Comments

@brandondahler
Copy link

brandondahler commented Sep 21, 2017

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

var expirationMode = ExpirationMode.Default;
var timeout = TimeSpan.Zero;

var cacheManager = 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

if (expirationMode != ExpirationMode.None && expirationMode != ExpirationMode.Default && timeout == TimeSpan.Zero)

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.

@MichaCo
Copy link
Owner

MichaCo commented Oct 16, 2017

Totally forgot to post an answer to this -.- Thanks for the very detailed report!
I will look into this

@MichaCo MichaCo added the bug label Oct 16, 2017
@MichaCo MichaCo added this to the 1.1.2 milestone Nov 18, 2017
MichaCo added a commit that referenced this issue Nov 18, 2017
@MichaCo
Copy link
Owner

MichaCo commented Nov 18, 2017

fixed in release 1.1.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants