ConcurrentDictionary.GetOrAdd Always Executes Delegate Method

The reason you’re seeing this is that you are not passing CacheValueFactory as a delegate but instead evaluating the function promptly and passing the resulting value. This causes you to use the overload which accepts a key and value and not the one which accepts a key and delegate.

To use the delegate version switch the code to the following

string val = _cache.GetOrAdd(key, CacheValueFactory);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)