/// <summary> /// 缓存键值操作。 /// </summary> /// <param name="cache">缓存对象。</param> /// <param name="entity">当前实体对象。</param> /// <param name="field">当前字段。</param> /// <param name="func">缓存求值委托。</param> /// <returns>返回</returns> protected virtual object CacheFunc(IDataBinderObjectCache cache, object entity, string field, CacheValueFunc func) { if (cache != null && AllowCache) { object value; if (!cache.Get(entity, field, out value)) { value = func(); cache.Set(entity, field, value); } return(value); } else { return(func()); } }
public void Bind(IDataContext dataContext, System.Data.IDataReader dataReader, object entity, IDataBinderObjectCache cache) { if (cache != null && binder.AllowCache) { object value; if (!cache.Get(entity, propertyInfo.Name, out value)) { value = binder.Bind(dataContext, dataReader, entity, propertyInfo.Name, propertyInfo.PropertyType, cache); cache.Set(entity, propertyInfo.Name, value); } propertyInfo.SetValue(entity, value, null); } else { var value2 = binder.Bind(dataContext, dataReader, entity, propertyInfo.Name, propertyInfo.PropertyType, cache); propertyInfo.SetValue(entity, value2, null); } }
/// <summary> /// 缓存键值操作。 /// </summary> /// <param name="cache">缓存对象。</param> /// <param name="builder">select命令构造器。</param> /// <param name="tag">标记。</param> /// <param name="type">类型。</param> /// <param name="func">缓存求值委托。</param> /// <returns>返回</returns> protected virtual object CacheFunc(IDataBinderObjectCache cache, Symbol.Data.ISelectCommandBuilder builder, string tag, Type type, CacheValueFunc func) { if (cache != null && AllowCache) { object value; string key = BuildCacheKey(builder, tag, type); if (!cache.Get(key, out value)) { value = func(); cache.Set(key, value); } return(value); } else { return(func()); } }