zeppaman / Owin-Nancy-Tutorial

Tutorial for creating a Owin module using Nancy as rendering engine.
0 stars 0 forks source link

Benefit of ConcurrentDictionary lost if you don't use valueFactory version. #1

Open jsuddsjr opened 7 years ago

jsuddsjr commented 7 years ago

At EmbeddedStaticContentConventionBuilder.cs#L63, you attempt to cache the returned Func<Response> object in a ConcurrentDictionary, but you are invoking the helper method every time before calling the GetOrAdd function.

If you were to replace this direct call to BuildContentDelegate with a Func<TKey, TValue> call, then GetOrAdd will not invoke the method unless the key is not found in the dictionary. See MSDN for ConcurrentDictionary<TKey, TValue>.GetOrAdd Method (TKey, Func<TKey, TValue>).

zeppaman commented 7 years ago

You are right. I agree with you, it is a mistake. Thanks for reporting this, I'm going to fix it.