/// <summary> /// 根据某字段 从缓存中 查询所有未删除经排序后的实例集合 /// </summary> /// <param name="type">实例的类型</param> /// <param name="fieldStr">字段字符串:“CourseId=1" </param> /// <param name="fieldValue">该字段的值:1</param> /// <param name="status">状态:1正常,2禁用,3删除</param> /// <param name="fieldOrder">排序字段:"NO"</param> /// <returns>从缓存中 查询所有未删除经排序后的实例集合</returns> public List<object> SelectModelByCacleByField(Type type, string fieldStr, object fieldValue, long status, string fieldOrder) { string className = type.Name; string cacle_key = className + fieldValue; List<object> list = (List<object>)HttpRuntime.Cache[cacle_key]; if (list==null || list.Count <= 0) //如果缓存中没有就从DB中获取 { List<object> listDB = new MyORM_BLL().SelectModelByField(type, fieldStr, status, fieldOrder); if (listDB.Count > 0) //把数据库中获得的数据进行缓存 { int ModelCache = Convert.ToInt32(ConfigurationManager.AppSettings["ModelCache"]); HttpRuntime.Cache.Insert(cacle_key, listDB, null, DateTime.Now.AddSeconds(ModelCache), TimeSpan.Zero); } list = listDB; } return list; } /// <summary> /// 根据ID 从缓存中 查询未删除的实例 /// </summary> /// <param name="type">实例类型</param> /// <param name="status">状态:1正常,2禁用,3删除</param> /// <param name="id">实例ID</param> /// <returns>从缓存中 查询未删除的实例</returns> public object SelectModelByCacheById(Type type, long status, int id) { string className = type.Name; string cacle_key = className + id; object obj = (object)HttpRuntime.Cache[cacle_key]; if (obj == null) //如果缓存中没有就从DB中获取 { object objDB = new MyORM_BLL().SelectModelById(type, status, id); if (objDB != null) //把数据库中获得的数据进行缓存 { int ModelCache = Convert.ToInt32(ConfigurationManager.AppSettings["ModelCache"]); HttpRuntime.Cache.Insert(cacle_key, objDB, null, DateTime.Now.AddSeconds(ModelCache), TimeSpan.Zero); } obj = objDB; } return obj; }