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.

適用於

另請參閱