public T Request <T>(PrimaryKey?id) where T : Entity { if (id == null) { return(null); } IdentityTuple tuple = new IdentityTuple(typeof(T), id.Value); Entity ident; if (entityCache.TryGetValue(tuple, out ident)) { return((T)ident); } if (retrieved.TryGetValue(tuple, out ident)) { return((T)ident); } ICacheController cc = Schema.Current.CacheController(typeof(T)); if (cc != null && cc.Enabled) { T entityFromCache = EntityCache.Construct <T>(id.Value); cc.Complete(entityFromCache, this); retrieved.Add(tuple, entityFromCache); return(entityFromCache); } ident = (T)requests?.TryGetC(typeof(T))?.TryGetC(id.Value); if (ident != null) { return((T)ident); } T entity = EntityCache.Construct <T>(id.Value); if (requests == null) { requests = new Dictionary <Type, Dictionary <PrimaryKey, Entity> >(); } requests.GetOrCreate(tuple.Type).Add(tuple.Id, entity); return(entity); }
public T Complete <T>(PrimaryKey?id, Action <T> complete) where T : Entity { if (id == null) { return(null); } IdentityTuple tuple = new IdentityTuple(typeof(T), id.Value); Entity result; if (entityCache.TryGetValue(tuple, out result)) { return((T)result); } if (retrieved.TryGetValue(tuple, out result)) { return((T)result); } T entity; if (TryGetRequest(tuple, out result)) { entity = (T)result; requests[typeof(T)].Remove(id.Value); } else { entity = EntityCache.Construct <T>(id.Value); } retrieved.Add(tuple, entity); complete(entity); return(entity); }
public T Request <T>(PrimaryKey?id) where T : Entity { if (id == null) { return(null); } IdentityTuple tuple = new IdentityTuple(typeof(T), id.Value); Entity ident; if (entityCache.TryGetValue(tuple, out ident)) { return((T)ident); } if (retrieved.TryGetValue(tuple, out ident)) { return((T)ident); } ident = (T)requests?.TryGetC(typeof(T))?.TryGetC(id.Value); if (ident != null) { return((T)ident); } T entity = EntityCache.Construct <T>(id.Value); if (requests == null) { requests = new Dictionary <Type, Dictionary <PrimaryKey, Entity> >(); } requests.GetOrCreate(tuple.Type).Add(tuple.Id, entity); return(entity); }