/// <summary> /// 从缓存获取获取实体 /// </summary> /// <param name="id">主键</param> public static BaseUserEntity GetObjectByCache(string id) { BaseUserEntity result = null; System.Web.Caching.Cache cache = HttpRuntime.Cache; string cacheObject = "User"; if (!string.IsNullOrEmpty(id)) { cacheObject = "User" + id; } if (cache == null || cache[cacheObject] == null) { BaseUserManager manager = new DotNet.Business.BaseUserManager(BaseUserEntity.TableName); result = manager.GetObject(id); // 若是空的不用缓存,继续读取实体 if (result != null) { cache.Add(cacheObject, result, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Normal, null); // System.Console.WriteLine(System.DateTime.Now.ToString(BaseSystemInfo.DateTimeFormat) + " cache User " + id); } } result = cache[cacheObject] as BaseUserEntity; return(result); }