BusterWood.Caching/CacheExtensions.cs
/// <summary>Tries to add a value to the cache, returns TRUE if the value was added, FALSE if the cache already contains an value for this key</summary>
Tries to add a value to the cache, returns TRUE if the value was added, FALSE if the cache already contains an value for this key
Tries to add a value to the cache returns TRUE if the value was added FALSE if the cache already contains an value for this key
public static bool TryAdd<TKey, TValue>(this ICache<TKey, TValue> cache, TKey key, TValue value) where TValue : class
        {
            if (cache == null) throw new ArgumentNullException(nameof(cache));
            if (value == null) throw new ArgumentNullException(nameof(value));
            lock (cache.SyncRoot)
            {
                var existing = cache[key];
                if (value == null)
                {
                    cache[key] = value;
                    return true;
                }
                return false;
            }
        }
public static bool TryAdd < TKey , TValue > ( this ICache < TKey , TValue > cache , TKey key , TValue value ) where TValue : class { if ( cache == null ) throw new ArgumentNullException ( nameof ( cache ) ) ; if ( value == null ) throw new ArgumentNullException ( nameof ( value ) ) ; lock ( cache . SyncRoot ) { var existing = cache [ key ] ; if ( value == null ) { cache [ key ] = value ; return true ; } return false ; } }
Tries to add a value to the cache, returns TRUE if the value was added, FALSE if the cache already contains an value for this key
Tries to add a value to the cache returns TRUE if the value was added FALSE if the cache already contains an value for this key
ICache<TKey, TValue>
this
key
TKey
value
TValue