CacheSection Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Konfigurerar globala cacheinställningar för ett ASP.NET-program. Det går inte att ärva den här klassen.
public ref class CacheSection sealed : System::Configuration::ConfigurationSection
public sealed class CacheSection : System.Configuration.ConfigurationSection
type CacheSection = class
inherit ConfigurationSection
Public NotInheritable Class CacheSection
Inherits ConfigurationSection
- Arv
Exempel
I följande kodexempel visas en sida och den relaterade kodfilen som används för att komma åt avsnittsattributen CacheSection .
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReadWriteCache.aspx.cs" Inherits="ReadWriteCache" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Read Write Application Cache</title>
</head>
<body>
<form id="form1" runat="server">
<h2>Read Write Application Cache</h2>
<asp:Label ID="Label1" Text="[Application Cache goes here.]" runat="server"></asp:Label>
<hr />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Write Cache" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Read Cache" />
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ReadWriteCache.aspx.vb" Inherits="ReadWriteCache" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Read Write Application Cache</title>
</head>
<body>
<form id="form1" runat="server">
<h2>Read Write Application Cache</h2>
<asp:Label ID="Label1" Text="[Application Cache goes here.]" runat="server"></asp:Label>
<hr />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Write Cache" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Read Cache" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class ReadWriteCache : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Label1.Text = "Application Cache goes here.";
}
protected void Button1_Click(object sender, EventArgs e)
{
// Get the application configuration file.
System.Configuration.Configuration config =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
System.Web.Configuration.CacheSection cacheSection =
(System.Web.Configuration.CacheSection)config.GetSection(
"system.web/caching/cache");
// Increase the PrivateBytesLimit property to 0.
cacheSection.PrivateBytesLimit =
cacheSection.PrivateBytesLimit + 10;
// Increase memory limit.
cacheSection.PercentagePhysicalMemoryUsedLimit =
cacheSection.PercentagePhysicalMemoryUsedLimit + 1;
// Increase poll time.
cacheSection.PrivateBytesPollTime =
cacheSection.PrivateBytesPollTime + TimeSpan.FromMinutes(1);
// Enable or disable memory collection.
cacheSection.DisableMemoryCollection =
!cacheSection.DisableMemoryCollection;
// Enable or disable cache expiration.
cacheSection.DisableExpiration =
!cacheSection.DisableExpiration;
// Save the configuration file.
config.Save(System.Configuration.ConfigurationSaveMode.Modified);
}
protected void Button2_Click(object sender, EventArgs e)
{
// Get the application configuration file.
System.Configuration.Configuration config =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
System.Web.Configuration.CacheSection cacheSection =
(System.Web.Configuration.CacheSection)config.GetSection(
"system.web/caching/cache");
// Read the cache section.
System.Text.StringBuilder buffer = new System.Text.StringBuilder();
string currentFile = cacheSection.CurrentConfiguration.FilePath;
bool dExpiration = cacheSection.DisableExpiration;
bool dMemCollection = cacheSection.DisableMemoryCollection;
TimeSpan pollTime = cacheSection.PrivateBytesPollTime;
int phMemUse = cacheSection.PercentagePhysicalMemoryUsedLimit;
long pvBytesLimit = cacheSection.PrivateBytesLimit;
string cacheEntry = String.Format("File: {0} <br/>", currentFile);
buffer.Append(cacheEntry);
cacheEntry = String.Format("Expiration Disabled: {0} <br/>", dExpiration);
buffer.Append(cacheEntry);
cacheEntry = String.Format("Memory Collection Disabled: {0} <br/>", dMemCollection);
buffer.Append(cacheEntry);
cacheEntry = String.Format("Poll Time: {0} <br/>", pollTime.ToString());
buffer.Append(cacheEntry);
cacheEntry = String.Format("Memory Limit: {0} <br/>", phMemUse.ToString());
buffer.Append(cacheEntry);
cacheEntry = String.Format("Bytes Limit: {0} <br/>", pvBytesLimit.ToString());
buffer.Append(cacheEntry);
Label1.Text = buffer.ToString();
}
}
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Partial Public Class ReadWriteCache
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Label1.Text = "Application Cache goes here."
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
' Get the application configuration file.
Dim config As System.Configuration.Configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/")
Dim cacheSection As System.Web.Configuration.CacheSection =
CType(config.GetSection("system.web/caching/cache"), System.Web.Configuration.CacheSection)
' Increase the PrivateBytesLimit property to 0.
cacheSection.PrivateBytesLimit = cacheSection.PrivateBytesLimit + 10
' Increase memory limit.
cacheSection.PercentagePhysicalMemoryUsedLimit =
cacheSection.PercentagePhysicalMemoryUsedLimit + 1
' Increase poll time.
cacheSection.PrivateBytesPollTime =
cacheSection.PrivateBytesPollTime + TimeSpan.FromMinutes(1)
' Enable or disable memory collection.
cacheSection.DisableMemoryCollection =
Not cacheSection.DisableMemoryCollection
' Enable or disable cache expiration.
cacheSection.DisableExpiration =
Not cacheSection.DisableExpiration
' Save the configuration file.
config.Save(System.Configuration.ConfigurationSaveMode.Modified)
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
' Get the application configuration file.
Dim config As System.Configuration.Configuration =
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/")
Dim cacheSection As System.Web.Configuration.CacheSection =
CType(config.GetSection("system.web/caching/cache"), System.Web.Configuration.CacheSection)
' Read the cache section.
Dim buffer As New System.Text.StringBuilder()
Dim currentFile As String = cacheSection.CurrentConfiguration.FilePath
Dim dExpiration As Boolean = cacheSection.DisableExpiration
Dim dMemCollection As Boolean = cacheSection.DisableMemoryCollection
Dim pollTime As TimeSpan = cacheSection.PrivateBytesPollTime
Dim phMemUse As Integer = cacheSection.PercentagePhysicalMemoryUsedLimit
Dim pvBytesLimit As Long = cacheSection.PrivateBytesLimit
Dim cacheEntry As String = String.Format("File: {0} <br/>", currentFile)
buffer.Append(cacheEntry)
cacheEntry = String.Format("Expiration Disabled: {0} <br/>", dExpiration)
buffer.Append(cacheEntry)
cacheEntry = String.Format("Memory Collection Disabled: {0} <br/>", dMemCollection)
buffer.Append(cacheEntry)
cacheEntry = String.Format("Poll Time: {0} <br/>", pollTime.ToString())
buffer.Append(cacheEntry)
cacheEntry = String.Format("Memory Limit: {0} <br/>", phMemUse.ToString())
buffer.Append(cacheEntry)
cacheEntry = String.Format("Bytes Limit: {0} <br/>", pvBytesLimit.ToString())
buffer.Append(cacheEntry)
Label1.Text = buffer.ToString()
End Sub
End Class
Kommentarer
Klassen CacheSection ger ett sätt att programmatiskt komma åt och ändra avsnittet i <cache> en konfigurationsfil.
Funktionen ASP.NET cachelagring implementeras av klassen Cache. Mer information finns i Cachelagring.
Note
CacheSection Kan skriva information till det relaterade avsnittet i konfigurationsfilen enligt de begränsningar som definieras av avsnittsegenskapen AllowDefinition vars värde är MachineToApplication. Försök att skriva i en konfigurationsfil på en nivå som inte tillåts i hierarkin resulterar i ett felmeddelande som genereras av parsern. Du kan dock använda den här klassen för att läsa konfigurationsinformation på valfri nivå i hierarkin.
En cache är en programspecifik hash-tabell som används för att lagra data som används ofta. Program- och sessionstillståndet liknar cachen, och programtillståndet är det mest lika på grund av dess programomfattande omfång. En av de största skillnaderna mellan cachen och mekanismen för programtillstånd är att cachen stöder beroenden Dessa beroenden gör det möjligt att skapa program som automatiskt tar bort cachelagrade objekt när vissa händelser inträffar.
Konstruktorer
| Name | Description |
|---|---|
| CacheSection() |
Initierar en ny instans av CacheSection klassen. |
Egenskaper
| Name | Description |
|---|---|
| CurrentConfiguration |
Hämtar en referens till den översta instansen Configuration som representerar konfigurationshierarkin som den aktuella ConfigurationElement instansen tillhör. (Ärvd från ConfigurationElement) |
| DefaultProvider |
Hämtar eller anger standardprovidern. |
| DisableExpiration |
Hämtar eller anger ett värde som anger om cacheförfallotiden är inaktiverad. |
| DisableMemoryCollection |
Hämtar eller anger ett värde som anger om cacheminnessamlingen är inaktiverad. |
| ElementInformation |
Hämtar ett ElementInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| ElementProperty |
Hämtar objektet ConfigurationElementProperty som representerar ConfigurationElement själva objektet. (Ärvd från ConfigurationElement) |
| EvaluationContext |
Hämtar ContextInformation-objektet för ConfigurationElement-objektet. (Ärvd från ConfigurationElement) |
| HasContext |
Hämtar ett värde som anger om egenskapen CurrentConfiguration är |
| Item[ConfigurationProperty] |
Hämtar eller anger en egenskap eller ett attribut för det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| Item[String] |
Hämtar eller anger en egenskap, ett attribut eller ett underordnat element i det här konfigurationselementet. (Ärvd från ConfigurationElement) |
| LockAllAttributesExcept |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockAllElementsExcept |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockAttributes |
Hämtar samlingen med låsta attribut. (Ärvd från ConfigurationElement) |
| LockElements |
Hämtar samlingen med låsta element. (Ärvd från ConfigurationElement) |
| LockItem |
Hämtar eller anger ett värde som anger om elementet är låst. (Ärvd från ConfigurationElement) |
| PercentagePhysicalMemoryUsedLimit |
Hämtar eller anger ett värde som anger den maximala procentandelen virtuell minnesanvändning. |
| PrivateBytesLimit |
Hämtar eller anger ett värde som anger den maximala storleken på det privata arbetsprocessutrymmet. |
| PrivateBytesPollTime |
Hämtar eller anger ett värde som anger tidsintervallet mellan avsökningen för minnesanvändningen för arbetsprocessen. |
| Properties |
Hämtar samlingen med egenskaper. (Ärvd från ConfigurationElement) |
| Providers |
Hämtar providerns inställningssamling. |
| SectionInformation |
Hämtar ett SectionInformation objekt som innehåller den icke-anpassningsbara informationen och funktionerna i ConfigurationSection objektet. (Ärvd från ConfigurationSection) |
Metoder
| Name | Description |
|---|---|
| DeserializeElement(XmlReader, Boolean) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationElement) |
| DeserializeSection(XmlReader) |
Läser XML från konfigurationsfilen. (Ärvd från ConfigurationSection) |
| Equals(Object) |
Jämför den aktuella ConfigurationElement instansen med det angivna objektet. (Ärvd från ConfigurationElement) |
| GetHashCode() |
Hämtar ett unikt värde som representerar den aktuella ConfigurationElement instansen. (Ärvd från ConfigurationElement) |
| GetRuntimeObject() |
Returnerar ett anpassat objekt när det åsidosättas i en härledd klass. (Ärvd från ConfigurationSection) |
| GetTransformedAssemblyString(String) |
Returnerar den transformerade versionen av det angivna sammansättningsnamnet. (Ärvd från ConfigurationElement) |
| GetTransformedTypeString(String) |
Returnerar den transformerade versionen av det angivna typnamnet. (Ärvd från ConfigurationElement) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| Init() |
Anger objektets ConfigurationElement ursprungliga tillstånd. (Ärvd från ConfigurationElement) |
| InitializeDefault() |
Används för att initiera en standarduppsättning med värden för ConfigurationElement objektet. (Ärvd från ConfigurationElement) |
| IsModified() |
Anger om det här konfigurationselementet har ändrats sedan det senast sparades eller lästes in när det implementerades i en härledd klass. (Ärvd från ConfigurationSection) |
| IsReadOnly() |
Hämtar ett värde som anger om objektet ConfigurationElement är skrivskyddat. (Ärvd från ConfigurationElement) |
| ListErrors(IList) |
Lägger till felen invalid-property i det här ConfigurationElement objektet, och i alla underelement, i den överförda listan. (Ärvd från ConfigurationElement) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| OnDeserializeUnrecognizedAttribute(String, String) |
Hämtar ett värde som anger om ett okänt attribut påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnDeserializeUnrecognizedElement(String, XmlReader) |
Hämtar ett värde som anger om ett okänt element påträffas under deserialiseringen. (Ärvd från ConfigurationElement) |
| OnRequiredPropertyNotFound(String) |
Utlöser ett undantag när en obligatorisk egenskap inte hittas. (Ärvd från ConfigurationElement) |
| PostDeserialize() |
Anropas efter deserialisering. (Ärvd från ConfigurationElement) |
| PreSerialize(XmlWriter) |
Anropas före serialisering. (Ärvd från ConfigurationElement) |
| Reset(ConfigurationElement) |
Återställer objektets interna tillstånd ConfigurationElement , inklusive låsen och egenskapssamlingarna. (Ärvd från ConfigurationElement) |
| ResetModified() |
Återställer värdet för metoden till |
| SerializeElement(XmlWriter, Boolean) |
Skriver innehållet i det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SerializeSection(ConfigurationElement, String, ConfigurationSaveMode) |
Skapar en XML-sträng som innehåller en icke-komprimerad vy av ConfigurationSection objektet som ett enda avsnitt för att skriva till en fil. (Ärvd från ConfigurationSection) |
| SerializeToXmlElement(XmlWriter, String) |
Skriver de yttre taggarna för det här konfigurationselementet till konfigurationsfilen när det implementeras i en härledd klass. (Ärvd från ConfigurationElement) |
| SetPropertyValue(ConfigurationProperty, Object, Boolean) |
Anger en egenskap till det angivna värdet. (Ärvd från ConfigurationElement) |
| SetReadOnly() |
Anger egenskapen IsReadOnly() för ConfigurationElement objektet och alla underelement. (Ärvd från ConfigurationElement) |
| ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName) |
Anger om det angivna elementet ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement) |
Anger om den angivna egenskapen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ShouldSerializeSectionInTargetVersion(FrameworkName) |
Anger om den aktuella ConfigurationSection-instansen ska serialiseras när konfigurationsobjekthierarkin serialiseras för den angivna målversionen av .NET Framework. (Ärvd från ConfigurationSection) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |
| Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode) |
Ändrar objektet ConfigurationElement för att ta bort alla värden som inte ska sparas. (Ärvd från ConfigurationElement) |