緩衝 Data Cache

來源:互聯網
上載者:User

    Output Cache 只適用於同一份asp.net網頁,如果要跨網頁共用某些緩衝內容(如:資料連線、DataSet、DataView),就要使用緩衝引擎中的緩衝對象(Cache Object)。
    緩衝對象可以直接和緩衝引擎溝通,即是提供緩衝引擎的直接存取操作,並且可讓多份asp.net網頁共用,同時允許彼此建立、修改、刪除其中的內容。對WEB應用程式而言,Cache對象是私人的(Private)而非公有(public),因此無法跨越不同的應用程式共用Cache對象的內容。

一、Cache對象的處理
    Cache對象和Session、Application對象相似,分為添加和刪除兩種操作,前者和session對象相同(或使用insert方法),後者是通過Cache對象的Remove方法。
    如果想要添加某個Cache對象,例如作者姓名,語句如下:

Cache["Author"]="allonkwok"

    而要取出某個Cache對象的內容時,可藉助一個變數,或直接以Response.Write方法列出,如下:

string strAuthor;
strAuthor=Cache("Author");
Response.Write[strAuthor];

    下面我們以一個例子示範如何迴圈取出Cache對象內容:

<%@ Import Namespace="System.Web.Caching.Cache"%>
<Script Language="C#" runat="server">
    public void Page_Load(object sender,EventArgs e)
    {
        Object objCache;
        string strText;

        Cache["Author"]="allonkwok";
        Cache["City"]="amoi";
        Cache["Phone"]="05921234567";

        foreach (objCache In Cache)
        {
            if IndexOf(objCache.Key.Substring(1,7),1)<1
                {
                    strText &=objCache.Key&"="&Cache(objCache.Key)&"<br>";
                }
        }
            lblShow.Text=strText;
    }
</script>
<html>
<body>
<asp:Label id="lblShow" runat="server"/>
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.