CacheItemPriority CacheItemPriority CacheItemPriority CacheItemPriority Enum

定义

指定 Cache 对象中存储的项的相对优先级。Specifies the relative priority of items stored in the Cache object.

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

字段

AboveNormal AboveNormal AboveNormal AboveNormal 4

在服务器释放系统内存时,具有该优先级级别的缓存项被删除的可能性比分配了 Normal 优先级的项要小。Cache items with this priority level are less likely to be deleted as the server frees system memory than those assigned a Normal priority.

BelowNormal BelowNormal BelowNormal BelowNormal 2

在服务器释放系统内存时,具有该优先级级别的缓存项比分配了 Normal 优先级的项更有可能从缓存中删除。Cache items with this priority level are more likely to be deleted from the cache as the server frees system memory than items assigned a Normal priority.

Default Default Default Default 3

缓存项优先级的默认值为 NormalThe default value for a cached item's priority is Normal.

High High High High 5

在服务器释放系统内存时,具有该优先级级别的缓存项最不可能从缓存中删除。Cache items with this priority level are the least likely to be deleted from the cache as the server frees system memory.

Low Low Low Low 1

在服务器释放系统内存时,具有该优先级级别的缓存项最有可能从缓存中删除。Cache items with this priority level are the most likely to be deleted from the cache as the server frees system memory.

Normal Normal Normal Normal 3

在服务器释放系统内存时,具有该优先级级别的缓存项很有可能从缓存中删除,其被删除的可能性仅次于具有 LowBelowNormal 优先级的那些项。Cache items with this priority level are likely to be deleted from the cache as the server frees system memory only after those items with Low or BelowNormal priority. 这是默认设置。This is the default.

NotRemovable NotRemovable NotRemovable NotRemovable 6

在服务器释放系统内存时,具有该优先级级别的缓存项将不会自动从缓存删除。The cache items with this priority level will not be automatically deleted from the cache as the server frees system memory. 但是,具有该优先级级别的项会根据项的绝对到期时间或可调整到期时间与其他项一起移除。However, items with this priority level are removed along with other items according to the item's absolute or sliding expiration time.

示例

下面的代码示例使用Insert方法添加到项Insert对象,其priority参数设置为高。The following code example uses the Insert method to add an item to the Insert object with its priority parameter set to 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对象有选择地清除项来释放系统内存。When the Web server hosting an ASP.NET application runs low on memory, the Cache object selectively purges items to free system memory. 项添加到缓存中,可以将其分配与存储在缓存中的其他项比较的相对优先级。When an item is added to the cache, you can assign it a relative priority compared to the other items stored in the cache. 向其分配更高的优先级值不太可能会从缓存中删除时服务器在处理大量请求,而向其分配较低优先级值的项是更有可能被删除的项。Items to which you assign higher priority values are less likely to be deleted from the cache when the server is processing a large number of requests, whereas items to which you assign lower priority values are more likely to be deleted. 默认值为 Normal。The default is Normal.

备注

项可以始终是从缓存中删除以编程方式,而不考虑其缓存优先级。Items can always be removed from the cache programmatically, regardless of their cache priority.

适用于

另请参阅