BusterWood.Caching/CacheExtensions.cs
/// <summary>Gets the existing value in the cache or adds a new value created by the <paramref name="valueFactory"/></summary>
Gets the existing value in the cache or adds a new value created by the
Gets the existing value in the cache or adds a new value created by the
public static TValue GetOrAdd<TKey, TValue>(this ICache<TKey, TValue> cache, TKey key, Func<TKey, TValue> valueFactory) where TValue : class
        {
            if (cache == null) throw new ArgumentNullException(nameof(cache));
            if (valueFactory == null) throw new ArgumentNullException(nameof(valueFactory));
            lock (cache.SyncRoot)
            {
                var value = cache[key];
                if (value == null)
                    cache[key] = value = valueFactory(key);
                return value;
            }
        }
public static TValue GetOrAdd < TKey , TValue > ( this ICache < TKey , TValue > cache , TKey key , Func < TKey , TValue > valueFactory ) where TValue : class { if ( cache == null ) throw new ArgumentNullException ( nameof ( cache ) ) ; if ( valueFactory == null ) throw new ArgumentNullException ( nameof ( valueFactory ) ) ; lock ( cache . SyncRoot ) { var value = cache [ key ] ; if ( value == null ) cache [ key ] = value = valueFactory ( key ) ; return value ; } }
Gets the existing value in the cache or adds a new value created by the
Gets the existing value in the cache or adds a new value created by the
ICache<TKey, TValue>
this
key
TKey
valueFactory
Func<TKey, TValue>