.NET Framework 类库
CacheItemPriority 枚举

更新:2007 年 11 月

指定 Cache 对象中存储的项的相对优先级。

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

语法

Visual Basic(声明)
Public Enumeration CacheItemPriority
Visual Basic (用法)
Dim instance As CacheItemPriority
C#
public enum CacheItemPriority
Visual C++
public enum class CacheItemPriority
J#
public enum CacheItemPriority
JScript
public enum CacheItemPriority
成员

成员名称说明
Low在服务器释放系统内存时,具有该优先级级别的缓存项最有可能被从缓存删除。
BelowNormal在服务器释放系统内存时,具有该优先级级别的缓存项比分配了 Normal 优先级的项更有可能被从缓存删除。
Normal在服务器释放系统内存时,具有该优先级级别的缓存项很有可能被从缓存删除,其被删除的可能性仅次于具有 LowBelowNormal 优先级的那些项。这是默认选项。
AboveNormal在服务器释放系统内存时,具有该优先级级别的缓存项被删除的可能性比分配了 Normal 优先级的项要小。
High在服务器释放系统内存时,具有该优先级级别的缓存项最不可能被从缓存删除。
NotRemovable在服务器释放系统内存时,具有该优先级级别的缓存项将不会被自动从缓存删除。但是,具有该优先级级别的项会根据项的绝对到期时间或可调整到期时间与其他项一起被移除。
Default缓存项优先级的默认值为 Normal
备注

当承载 ASP.NET 应用程序的 Web 服务器的运行缺少内存时,Cache 对象将有选择地清除项来释放系统内存。当向缓存添加项时,可以为其分配与缓存中存储的其他项相比较的相对优先级。在服务器处理大量请求时,分配了较高优先级值的项被从缓存删除的可能性较小,而分配了较低优先级值的项则更有可能被删除。默认为 Normal

说明:

无论项的缓存优先级如何,总能以编程方式从缓存中移除项。

示例

下面的代码示例使用 Insert 方法将一项添加到 Cache 对象中,该对象的 priority 参数设置为 High

Visual Basic
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    Public Sub Page_Load(sender As Object, e As EventArgs)
        Dim connectionString As String
        connectionString = "Data Source=localhost;Integrated Security=SSPI"
        Cache.Insert("DSN", connectionString, Nothing, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High, Nothing)
    End Sub
</script>
C#
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="c#" runat="server">
    public void Page_Load(Object sender, EventArgs e) {
        String connectionString;
        connectionString = "Data Source=localhost;Integrated Security=SSPI";
        Cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High, null);
    }
</script>
JScript
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="jscript" runat="server">
    public function Page_Load(sender : Object, e : EventArgs) : void  {
        var connectionString : String;
        connectionString = "Data Source=localhost;Integrated Security=SSPI";
        Cache.Insert("DSN", connectionString, null, DateTime.Now.AddMinutes(2), TimeSpan.Zero, CacheItemPriority.High, null);
    }
</script>
平台

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