/// <summary> /// 使用缓存查询信息 /// </summary> /// <param name="info">查询主体</param> /// <param name="totalcnt">返回条目数</param> /// <returns></returns> public DataTable QueryData(ActivitySearchEntity info, out int totalcnt) { if (info.UseDBPagination) { string key = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(info.ToJson(info), "MD5"); DataTableRSCacheEntity rsobj = MyCache <DataTableRSCacheEntity> .Get(key); if (rsobj == null) { DataTable dt = dao.QueryData(info, out totalcnt); if (dt != null && dt.Rows.Count > 0) { rsobj = new DataTableRSCacheEntity() { Source = dt, TotalCnt = totalcnt }; MyCache <DataTableRSCacheEntity> .Insert(key, rsobj, 60); } else { rsobj = new DataTableRSCacheEntity(); } } totalcnt = rsobj.TotalCnt; return(rsobj.Source); } else { return(dao.QueryData(info, out totalcnt)); } }
/// <summary> /// 获取展会所有展商地址 /// </summary> /// <param name="exhibitionID"></param> /// <returns></returns> public DataTable GetExhibitorLocation(int exhibitionID) { string key = string.Format(WebKeys.ExhibitorLocationConsoleCacheKey, exhibitionID.ToString()); DataTableRSCacheEntity rsobj = MyCache <DataTableRSCacheEntity> .Get(key); if (rsobj == null) { DataTable dt = dao.GetExhibitorLocation(exhibitionID); if (dt != null && dt.Rows.Count > 0) { rsobj = new DataTableRSCacheEntity() { Source = dt, TotalCnt = dt.Rows.Count }; MyCache <DataTableRSCacheEntity> .Insert(key, rsobj, 60); } else { rsobj = new DataTableRSCacheEntity(); } } return(rsobj.Source); //return dao.GetExhibitorLocation(exhibitionID); }
static void ShowResult(MyCache cache0, MyCache cache1, string key, string caption) { Console.WriteLine(caption); byte[] blob0 = cache0.Get(key), blob1 = cache1.Get(key); Console.WriteLine("{0} vs {1}", blob0 == null ? "(null)" : Encoding.UTF8.GetString(blob0), blob1 == null ? "(null)" : Encoding.UTF8.GetString(blob1) ); }
static void Main(string[] args) { IMyCache <int, String> cache = new MyCache <int, string>(2); cache.Put(10, "Value1"); cache.Put(9, "Value2"); cache.SetIgnoreTime(DateTime.Now); Console.WriteLine(cache.Get(10)); cache.Put(10, "Value3"); cache.Put(11, "Value4"); Console.WriteLine(cache.Get(10)); cache.Put(12, "Value5"); Console.WriteLine(cache.Get(10)); cache.Put(13, "Value6"); cache.Put(14, "Value7"); Console.WriteLine(cache.Get(10)); Console.ReadLine(); }
private string GetPublishFunctionTree() { string returnValue = ""; string cachekey = "__bb_allfunction_treehtml"; object o = MyCache <string> .Get(cachekey); if (o != null) { returnValue = o.ToString(); } else { List <FunctionEntity> list = this.SelectAllFunctions(); StringBuilder sbTree_Html = new StringBuilder(); List <FunctionEntity> k1 = list.FindAll((_k) => { return(_k.Function_Level == 1 && _k.Function_IsNew == 1 && _k.Function_isValid == 1); }); List <FunctionEntity> k2 = list.FindAll((_k) => { return(_k.Function_Level == 2 && _k.Function_IsNew == 1 && _k.Function_isValid == 1); }); foreach (FunctionEntity k in k1) { sbTree_Html.Append("<li class=\"open\"><input class=\"ace-checkbox-2\" type=\"checkbox\" checktype=\"public\" onclick=\"checkchange(this);\" level=\""); sbTree_Html.Append(k.Function_Level.ToString()); sbTree_Html.Append("\" value=\""); sbTree_Html.Append(k.Function_ID); sbTree_Html.Append("\" /><span>"); sbTree_Html.Append(k.Function_Name); sbTree_Html.Append("</span>"); List <FunctionEntity> thissubkinds = k2.FindAll((_k) => { return(_k.Function_ParentID == k.Function_ID); }); if (thissubkinds.Count > 0) { sbTree_Html.Append("<ul>"); foreach (FunctionEntity _subkind in thissubkinds) { sbTree_Html.Append("<li><input class=\"ace-checkbox-2\" type=\"checkbox\" checktype=\"public\" onclick=\"checkchange(this);\" level=\""); sbTree_Html.Append(_subkind.Function_Level.ToString()); sbTree_Html.Append("\" value=\""); sbTree_Html.Append(_subkind.Function_ID); sbTree_Html.Append("\" /><span>"); sbTree_Html.Append(_subkind.Function_Name); sbTree_Html.Append("</span>"); sbTree_Html.Append("</li>"); } sbTree_Html.Append("</ul>"); } sbTree_Html.Append("</li>"); } MyCache <string> .Insert(cachekey, sbTree_Html.ToString()); returnValue = sbTree_Html.ToString(); } return(returnValue); }
/// <summary> /// 以展场id为主键,查询所有展商 /// </summary> /// <param name="exhibitionID">展场id</param> /// <returns>展商List集合</returns> public List <ActivityToCustomerEntity> GetActivityEntityListUseMyCache(int exhibitionID) { string key = string.Format(WebKeys.ActivityCacheKey, exhibitionID.ToString()); List <ActivityToCustomerEntity> list = MyCache <List <ActivityToCustomerEntity> > .Get(key); if (list == null) { list = this.GetActivityEntityList(exhibitionID); MyCache <List <ActivityToCustomerEntity> > .Insert(key, list, 600); } return(list); }
/// <summary> /// 获得查询关键词使用缓存 /// </summary> /// <param name="exhibitionID"></param> /// <returns></returns> public List <SearchKeyWordEntity> GetSearchKeyWordEntityListUseMyCache(int exhibitionID) { string key = string.Format(WebKeys.SearchKeyWordyCacheKey, exhibitionID.ToString()); List <SearchKeyWordEntity> list = MyCache <List <SearchKeyWordEntity> > .Get(key); if (list == null) { list = this.GetSearchKeyWordEntityList(exhibitionID); MyCache <List <SearchKeyWordEntity> > .Insert(key, list, 600); } return(list); }
/// <summary> /// 判断邮件缓存名是否过期 /// 没过期 邮件线程不操作数据库继续休眠 /// 过期 邮件线程开始尝试从数据库读取未发邮件 /// </summary> /// <returns></returns> private bool IsExistsMailCacheName(bool w = true) { return(!string.IsNullOrEmpty(MyCache <string> .Get(cacheTimeoutName))); //Cache objCache = HttpRuntime.Cache; //if (objCache.Get(cacheTimeoutName) != null) //{ // lock (cacheobj2) // { // if (objCache.Get(cacheTimeoutName) != null) // { // return true; // } // } //} //return false; }
/// <summary> /// 得到春联 使用缓存 /// </summary> /// <param name="isReload"></param> /// <returns></returns> public List <FuImageEntity> GetFuImageEntityListWithCache(bool isReload = false) { string key = WebKeys.FuimageCacheKey; List <FuImageEntity> list = null; if (!isReload) { list = MyCache <List <FuImageEntity> > .Get(key); } if (list == null) { list = this.GetFuImageList(); MyCache <List <FuImageEntity> > .Insert(key, list, 60); } return(list); }
/// <summary> /// 得到春联 使用缓存 /// </summary> /// <param name="isReload"></param> /// <returns></returns> public List <CoupletGroupEntity> GetCoupletGroupEntityListWithCache(bool isReload = false) { string key = WebKeys.CoupletCacheKey; List <CoupletGroupEntity> list = null; if (!isReload) { list = MyCache <List <CoupletGroupEntity> > .Get(key); } if (list == null) { list = this.GetCoupletGroupEntityList(); MyCache <List <CoupletGroupEntity> > .Insert(key, list, 60); } return(list); }
public void TestCache() { var storage1 = new MyCache <int, string>(); var containsBefore1 = storage1.Contains(1); storage1.Upsert(1, "value1"); var containsAfter1 = storage1.Contains(1); var value1 = storage1.Get(1); var storage2 = new MyCache <int, string>(); var containsBefore2 = storage2.Contains(1); storage2.Upsert(1, "value2"); var containsAfter2 = storage2.Contains(1); var value2 = storage2.Get(1); }
/// <summary> /// 根据查询前三级分类 /// </summary> /// <param name="kid"></param> /// <returns></returns> public List <FunctionEntity> SelectAllFunctions() { string cache_key = "BB__AllFunction"; object o = MyCache <List <FunctionEntity> > .Get(cache_key); if (o == null) { DataTable dt = functiondao.GetAllFunction().Tables[0]; List <FunctionEntity> functions = new List <FunctionEntity>(); foreach (DataRow dr in dt.Rows) { FunctionEntity f = new FunctionEntity(); f.Function_URL_New = dr[7].ToString(); f.Function_ID = int.Parse(dr["Function_ID"].ToString()); f.Function_IsNew = int.Parse(dr["Function_IsNew"].ToString()); f.Function_isValid = int.Parse(dr["Function_isValid"].ToString()); f.Function_Level = int.Parse(dr["Function_Level"].ToString()); f.Function_Name = dr["Function_Name"].ToString(); f.Function_Order = dr["Function_Order"].ToString(); f.Function_ParentID = int.Parse(dr["Function_ParentID"].ToString()); f.Function_URL = dr["Function_URL"].ToString(); functions.Add(f); } if (functions.Count > 0) { MyCache <List <FunctionEntity> > .Insert(cache_key, functions); } return(functions); } else { return(o as List <FunctionEntity>); } }