internal void UpdateCache(Type sourceType, Type targetType, bool isConvertable, IConversionAttempt conversionAttempt) { if (this.IsCacheEnabled == false) { return; } lock (this.syncObj) { this.ReduceCacheSize(this.MaxCacheSize - 1); // -1 because we are about to insert a new item var key = new KeyValuePair <Type, Type>(sourceType, targetType); var value = new WeightedCacheResult(isCached: true, isConvertable: isConvertable, conversionAttempt: conversionAttempt); this.cache[key] = value; } }
/// <summary> /// Tries to get a CacheResult from given {sourceType, targetType} mapping. /// </summary> /// <returns>A CacheResult which indicates if and how the given {sourceType, targetType} mapping can be converted.</returns> internal CacheResult TryGetCachedValue(Type sourceType, Type targetType) { if (this.IsCacheEnabled == false) { return(new CacheResult(isCached: false)); } lock (this.syncObj) { WeightedCacheResult cacheResult = null; var key = new KeyValuePair <Type, Type>(sourceType, targetType); this.cache.TryGetValue(key, out cacheResult); if (cacheResult != null) { cacheResult.ReadAccessCount++; return(cacheResult); } return(new CacheResult(isCached: false)); } }
internal void UpdateCache(Type sourceType, Type targetType, bool isConvertable, IConversionAttempt conversionAttempt) { if (this.IsCacheEnabled == false) { return; } lock (this.syncObj) { this.ReduceCacheSize(this.MaxCacheSize - 1); // -1 because we are about to insert a new item var key = new KeyValuePair<Type, Type>(sourceType, targetType); var value = new WeightedCacheResult(isCached: true, isConvertable: isConvertable, conversionAttempt: conversionAttempt); this.cache[key] = value; } }