Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was 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

Description

@rmja

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.

Activity

  1. Tratcher commented on Jul 12, 2016

    @Tratcher
    Member

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

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

  2. added this to the 1.1.0 milestone on Jul 22, 2016
  3. BrennanConroy commented on Jul 25, 2016

    @BrennanConroy
    Member
  4. gdoron commented on Oct 1, 2016

    @gdoron

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions