国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Cache在aspx.cs和xxx.CS里的不同用法

2019-11-17 03:48:57
字體:
來源:轉載
供稿:網友

在普通aspx.cs代碼里可以用:

Cache cache = new Cache();

但在XXXX.CS里,就不能用上面的方式了,得用:

永不時間過期

HttpContext.Current.Cache.Insert("Name", "王翔", null, DateTime.MaxValue, TimeSpan.Zero, CacheItemPRiority.NotRemovable, null);

Name:Key

王翔:Value

null:表示沒有緩存依賴項

DateTime.MaxValue:時間的最大值(9999-99-99 12:59:59),表示不使用絕對時間過期策略

TimeSpan.Zero:表示不使用平滑過期

CacheItemPrority.NotRemovable:表示優先權為不刪除該Cache

null:不怎么用,就null吧

 asp.net

絕對時間過期 (10秒后,自動過期)

HttpContext.Current.Cache.Insert("Name", "王翔", null, DateTime.Now.AddSeconds(10), TimeSpan.Zero, CacheItemPriority.NotRemovable, null);

 

平滑時間過期 (連續10秒沒有訪問該緩存,則自動過期)

HttpContext.Current.Cache.Insert("Name", "王翔", null, DateTime.MaxValue, TimeSpan.FromSeconds(10));

 

緩存的更新策略

if (HttpContext.Current.Cache["UserCacheList"] != null)
            {
                ht = (Hashtable)HttpContext.Current.Cache["UserCacheList"];
                ht.Add(uId, HttpContext.Current.Cache["User" + uId]);

            }
            else
            {
                ht.Add(uId, HttpContext.Current.Cache["User" + uId]);
                //HttpContext.Current.Cache["UserCacheList"] = ht;
                HttpContext.Current.Cache.Insert("UserCacheList", ht, null, DateTime.MaxValue, TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
            }

 
http://www.survivalescaperooms.com/kingfly/archive/2010/02/26/1674318.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 呼图壁县| 巴里| 寻乌县| 海安县| 麦盖提县| 浙江省| 安图县| 从江县| 鲁山县| 门源| 凌海市| 习水县| 安平县| 怀安县| 平阴县| 上犹县| 航空| 衡水市| 阳东县| 普安县| 乌兰浩特市| 雷山县| 巴里| 亳州市| 吴忠市| 安泽县| 平顶山市| 昌平区| 青岛市| 白玉县| 名山县| 洱源县| 德钦县| 雷州市| 盐亭县| 同江市| 临高县| 湾仔区| 开原市| 阳城县| 柳河县|