using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Patcher { class Cache { public static readonly Cache instance = new Cache(); private readonly Dictionary storage = new Dictionary(); private Cache() { } public TValue GetValue(TKey key, Func creator) { if(!this.storage.ContainsKey(key)) { lock(this.storage) { if(!this.storage.ContainsKey(key)) { this.storage[key] = creator(); } } } return this.storage[key]; } } }