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
@rmja

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions