.NET Framework 类库
Page..::.Cache 属性

更新:2007 年 11 月

获取与该页驻留的应用程序关联的 Cache 对象。

命名空间:  System.Web.UI
程序集:  System.Web(在 System.Web.dll 中)

语法

Visual Basic(声明)
<BrowsableAttribute(False)> _
Public ReadOnly Property Cache As Cache
Visual Basic (用法)
Dim instance As Page
Dim value As Cache

value = instance.Cache
C#
[BrowsableAttribute(false)]
public Cache Cache { get; }
Visual C++
[BrowsableAttribute(false)]
public:
property Cache^ Cache {
    Cache^ get ();
}
J#
/** @property */
/** @attribute BrowsableAttribute(false) */
public Cache get_Cache()
JScript
public function get Cache () : Cache

属性值

类型:System.Web.Caching..::.Cache

与该页的应用程序关联的 Cache

异常

异常条件
HttpException

未创建 Cache 的实例。

备注

应用程序的 Cache 对象使您得以在后面的请求中存储和检索任意数据。缓存并不与特定页或用户会话关联。它主要用于增强应用程序的性能。有关更多信息,请参见 缓存应用程序数据。有关应用程序缓存和页输出缓存之间区别的更多信息,请参见 ASP.NET 缓存概述

示例

下面的代码示例使用 Page..::.Cache 属性将两个整数的和插入 System.Web.Caching..::.Cache 对象。然后,它使用 Cache..::.Get 方法检索该值,并将其写入一个 Label Web 服务器控件。

Visual Basic
' This is a simple page that demonstrates how to place a value
' in the cache from a page, and one way to retrieve the value.
' Declare two constants, myInt1 and myInt2 and set their values
' and declare a string variable, myValue.
Const myInt1 As Integer = 35
Const myInt2 As Integer = 77
Dim myValue As String


' When the page is loaded, the sum of the constants
' is placed in the cache and assigned a key, key1.
Sub Page_Load(sender As [Object], arg As EventArgs)
   Cache("key1")= myInt1 + myInt2
End Sub 'Page_Load


' When a user clicks a button, the sum associated
' with key1 is retrieved from the Cache using the 
' Cache.Get method. It is converted to a string
' and displayed in a Label Web server control.
Sub CacheBtn_Click(sender As Object, e As EventArgs)
  If Cache("key1") Is Nothing Then
   myLabel.Text = "That object is not cached."
  Else
   myValue = Cache.Get("key1").ToString()
   myLabel.Text = myValue
  End If
End Sub 'CacheBtn_Click
C#
// This is a simple page that demonstrates how to place a value
// in the cache from a page, and one way to retrieve the value.
// Declare two constants, myInt1 and myInt2 and set their values
// and declare a string variable, myValue.
const int myInt1 = 35;
const int myInt2 = 77;
string myValue;

// When the page is loaded, the sum of the constants
// is placed in the cache and assigned a key, key1.
void Page_Load(Object sender,  EventArgs arg) {
  Cache["key1"] = myInt1 + myInt2;

}

// When a user clicks a button, the sum associated
// with key1 is retrieved from the Cache using the
// Cache.Get method. It is converted to a string
// and displayed in a Label Web server control.
void CacheBtn_Click(object sender, EventArgs e) {
   if (Cache["key1"] == null) {
      myLabel.Text = "That object is not cached.";
   }
   else {
      myValue = Cache.Get("key1").ToString();
      myLabel.Text = myValue;
   }
}
平台

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.5、3.0、2.0、1.1、1.0
另请参见

参考

其他资源

标记 :


Page view tracker