CacheItemPriority 枚举

定义

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

public enum class CacheItemPriority
public enum CacheItemPriority
type CacheItemPriority = 
Public Enum CacheItemPriority
继承
CacheItemPriority

字段

AboveNormal 4

在服务器释放系统内存时,具有该优先级级别的缓存项被删除的可能性比分配了 Normal 优先级的项要小。

BelowNormal 2

在服务器释放系统内存时,具有该优先级级别的缓存项比分配了 Normal 优先级的项更有可能从缓存中删除。

Default 3

缓存项优先级的默认值为 Normal

High 5

在服务器释放系统内存时,具有该优先级级别的缓存项最不可能从缓存中删除。

Low 1

在服务器释放系统内存时,具有该优先级级别的缓存项最有可能从缓存中删除。

Normal 3

在服务器释放系统内存时,具有该优先级级别的缓存项很有可能从缓存中删除,其被删除的可能性仅次于具有 LowBelowNormal 优先级的那些项。 这是默认设置。

NotRemovable 6

在服务器释放系统内存时,具有该优先级级别的缓存项将不会自动从缓存删除。 但是,具有该优先级级别的项会根据项的绝对到期时间或可调整到期时间与其他项一起移除。

示例

以下示例使用 Cache.Insert 方法将项添加到 对象, Cachepriority 参数设置为 High

<!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>
<%@ 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>

注解

当托管 ASP.NET 应用程序的 Web 服务器内存不足时, Cache 对象有选择地清除项以释放系统内存。 将项添加到缓存时,可以为其分配相对于缓存中存储的其他项的相对优先级。 当服务器处理大量请求时,您为其分配较高优先级值的项不太可能从缓存中删除,而您分配较低优先级值的项则更有可能被删除。 默认为 Normal

注意

无论项的缓存优先级如何,始终都可以以编程方式从缓存中删除。

适用于

另请参阅