using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FLocal.Core { public class Cache { public static readonly Cache instance = new Cache(); private Dictionary cache; private Cache() { this.cache = new Dictionary(); } public T get(object id, Func getter) { if(!this.cache.ContainsKey(id)) { lock(id) { if(!this.cache.ContainsKey(id)) { this.cache[id] = getter(); } } } lock(id) { if(this.cache.ContainsKey(id)) { return this.cache[id]; } } return this.get(id, getter); } public void delete(object id) { lock(id) { if(this.cache.ContainsKey(id)) { this.cache.Remove(id); } } } } }