using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Obfuz.Utils { public class CachedDictionary { private readonly Func _valueFactory; private readonly Dictionary _cache = new Dictionary(); public CachedDictionary(Func valueFactory) { _valueFactory = valueFactory; } public V GetValue(K key) { if (!_cache.TryGetValue(key, out var value)) { value = _valueFactory(key); _cache[key] = value; } return value; } } }