快取的使用

2022-01-19 05:42:27 字數 1297 閱讀 4642

關於快取的方法即用法介紹,命名空間:system.web.caching。

第一、  cache中的add方法:

引數:cache.add(

string key,//cache中的鍵

object value,//cache中的值

cachedependency dependencies,//依賴的項,可以是某個檔案路徑無則為null

datetime absoluteexpiration,//絕對過期的時間

timespan slidingexpiration,//滑動過期的時間

cacheitempriority priority,//快取刪除的優先順序

cacheitemremovedcallback onremovecallback//移除呼叫的**函式物件時呼叫的委託(如果有)無則為null

例項:if (cache["key1"] == null)

第二、cache中的get方法:返回的是乙個物件object

cache.get("key1");

第三、cache中的getenumerator方法:檢索用於迴圈訪問包含在快取中的鍵設定及其值的字典列舉數。

idictionaryenumerator cacheenum = cache.getenumerator();

while (cacheenum.movenext())

第四、cache中insert方法

cache.insert("dsn", connectionstring, null, datetime.now.addminutes(2), timespan.zero, cacheitempriority.high, onremove);

備註:無法同時設定 absoluteexpiration 和 slidingexpiration 引數。如果要讓快取項在特定時間過期,可將 absoluteexpiration 引數設定為特定時間,並將 slidingexpiration 引數設定為 noslidingexpiration。

如果要讓快取項自最後一次訪問該項後的某段時間之後過期,可將 slidingexpiration 引數設定為過期間隔,並將 absoluteexpiration 引數設定為 noabsoluteexpiration

第五、cache中的remove方法:未找到則為null即空引用

if(cache["key1"] != null)

快取的使用

快取一直是web2.0應用的效能核心,快取大幅提高了應用qps,減少了資料庫的壓力,降低了rt,讓應用能夠飛起來。快取具有易於上手,難於精通的特點,快取失效的設計是整個快取應用的難點,在某些複雜情況,不適合的快取設計增加了系統出錯的可能。下面對快取使用的幾種典型情況做下分析。用於快取複雜演算法的不可...

快取的使用

asp.net快取主要分為 頁面快取 中庸 資料來源快取 最不靈活的 資料快取 靈活 這三種主要型別。頁面快取 給頁面新增 outputcache duration 15 varybyparam none 標籤就可以啟用頁面快取,這樣整個頁面的內容都會被快取,頁面中的asp.net 資料來源在快取期...

NSData快取的使用

nsstring filename testfilensfilemangager.txt nsarray paths nssearchpathfordirectoriesindomains nsdocumentdirectory nsuserdomainmask yes nsstring docum...