dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.54k stars 25.31k forks source link

Microsoft.Extensions.Caching.Memory docs should have more details about GetOrAdd* calling the factory multiple times #22615

Open ericsampson opened 3 years ago

ericsampson commented 3 years ago

Currently, there is one tiny mention in "Additional Notes" at the very bottom of this page that the factory used by GetOrCreate and GetOrCreateAsync can be called multiple times.

As can be seen in this GH issue, and from my own experience, people often get tripped up by this fact.

Also, the examples in this document that show non-atomic use of TryGetValue and Set, such as the CacheTryGetValueSet() example and multiple more, are showing a bad pattern that is going to lead non-expert devs to write problematic code.

I would suggest:

Thanks!!


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

wadepickett commented 3 years ago

Thank you @ericsampson! Great to have your suggestions for improvements to this topic and the detailed examples are appreciated.