CacheItemPriority 枚举

定义

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

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

字段

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 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 3

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

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 1

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

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 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.

示例

下面Cache.Insert的示例使用方法将一个项添加Cache到对象中, 其priority参数设置为High:The following example uses the Cache.Insert method to add an item to the Cache 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. 默认值为 NormalThe default is Normal.

备注

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

适用于

另请参阅