CacheItemPriority Enum

Definition

Specifies the relative priority of items stored in the Cache object.

C#
public enum CacheItemPriority
Inheritance
CacheItemPriority

Fields

Name Value Description
Low 1

Cache items with this priority level are the most likely to be deleted from the cache as the server frees system memory.

BelowNormal 2

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

The default value for a cached item's priority is Normal.

Normal 3

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.

AboveNormal 4

Cache items with this priority level are less likely to be deleted as the server frees system memory than those assigned a Normal priority.

High 5

Cache items with this priority level are the least likely to be deleted from the cache as the server frees system memory.

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.

Examples

The following example uses the Cache.Insert method to add an item to the Cache object with its priority parameter set to High:

ASP.NET (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>

Remarks

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. The default is Normal.

Note

Items can always be removed from the cache programmatically, regardless of their cache priority.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also