Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

GetOrCreate / GetOrCreateAsync on IMemoryCache creates cache entry even when factory throws #211

Closed
rmja opened this issue Jul 12, 2016 · 3 comments
Assignees

Comments

@rmja
Copy link

rmja commented Jul 12, 2016

It seems wrong that a cache entry is added with the value null when the factory method throws:

            try
            {
                memoryCache.GetOrCreate("key", entry =>
                {
                    throw new Exception();
                    return 123;
                });
            } catch (Exception e)
            {
                // memoryCache now has an entry for "key" with the value null. This seems odd.
            }

The expected behaviour should be that the value is not added to the cache if the factory throws.

@Tratcher
Copy link
Member

Agreed. There should not be a using statement on this line:

using (var entry = cache.CreateEntry(key))

@BrennanConroy
Copy link
Member

18f2259

@gdoron
Copy link

gdoron commented Oct 1, 2016

When will preview 1 be released?
We just got hit hard by this bug, we'll might have to use the nightly builds on production 😢 until it's being released.

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

No branches or pull requests

5 participants