using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Web.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(); } } } try { return this.cache[id]; } catch(KeyNotFoundException) { return this.get(id, getter); } } public void delete(object id) { lock(id) { if(this.cache.ContainsKey(id)) { this.cache.Remove(id); } } } } }