public TValue GetOrInitializeValue(TKey key, InitializeValue initializeValue) { lock (cache) { CachedValue cachedValue; if (this.cache.TryGetValue(key, out cachedValue)) { return(cachedValue.Value); } TValue value = initializeValue.Invoke(key); this.cache.Add(key, new CachedValue(value)); if (this.cache.Count > this.maxValues) { int minID = int.MaxValue; TKey keyToRemove = default(TKey); foreach (System.Collections.Generic.KeyValuePair <TKey, CachedValue> kvp in this.cache) { if (kvp.Value.ID < minID) { minID = kvp.Value.ID; keyToRemove = kvp.Key; } } this.cache.Remove(keyToRemove); } return(value); } }
bool ICodeGenElementVisitor <bool> .VisitInitializeValue(InitializeValue initializeValue) { InitializeIfNecessary(GetValueSource(initializeValue.Variable), builder => ReadCodeGenValue(initializeValue.InputIndex)); return(true); }