国产探花免费观看_亚洲丰满少妇自慰呻吟_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://m.survivalescaperooms.com/kingfly/archive/2010/02/26/1674318.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 峨边| 乌鲁木齐县| 五原县| 宁河县| 孝昌县| 海阳市| 穆棱市| 柳林县| 炎陵县| 许昌市| 定远县| 库伦旗| 买车| 乌拉特中旗| 呼玛县| 东乌珠穆沁旗| 治多县| 丰城市| 偏关县| 西乡县| 沁阳市| 建德市| 寿阳县| 沈丘县| 金阳县| 阿拉善盟| 深圳市| 台江县| 垣曲县| 久治县| 巴马| 湟中县| 阜平县| 沙湾县| 延边| 晴隆县| 五大连池市| 霍城县| 涡阳县| 南乐县| 衡山县|