CacheSection Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Nakonfiguruje globální nastavení mezipaměti pro ASP.NET aplikaci. Tato třída se nemůže dědit.
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
- Dědičnost
Příklady
Následující příklad kódu ukazuje stránku a související soubor kódu použitý pro přístup k atributům oddílu 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
Poznámky
Třída CacheSection poskytuje způsob, jak programově přistupovat a upravovat <cache> oddíl konfiguračního souboru.
Funkci ASP.NET ukládání do mezipaměti implementuje třída Cache. Další informace naleznete v tématu Ukládání do mezipaměti.
Note
Může CacheSection zapsat informace do související části konfiguračního souboru podle omezení definovaných vlastností AllowDefinition oddílu, jejíž hodnota je MachineToApplication. Při každém pokusu o zápis do konfiguračního souboru na úrovni, která není v hierarchii povolená, se zobrazí chybová zpráva vygenerovaná analyzátorem. Tuto třídu však můžete použít ke čtení informací o konfiguraci na libovolné úrovni v hierarchii.
Mezipaměť je tabulka hash specifická pro aplikaci, která se používá k ukládání často používaných dat. Stav aplikace a relace jsou podobné mezipaměti, přičemž stav aplikace je nejvíce podobný vzhledem k rozsahu aplikace. Jedním z největších rozdílů mezi mezipamětí a mechanismem stavu aplikace je, že mezipaměť podporuje závislosti Tyto závislosti umožňují vytvářet aplikace, které automaticky odebírají položky uložené v mezipaměti, když dojde k určitým událostem.
Konstruktory
| Name | Description |
|---|---|
| CacheSection() |
Inicializuje novou instanci CacheSection třídy. |
Vlastnosti
| Name | Description |
|---|---|
| CurrentConfiguration |
Získá odkaz na instanci nejvyšší úrovně Configuration, která představuje hierarchii konfigurace, do které patří aktuální instance ConfigurationElement. (Zděděno od ConfigurationElement) |
| DefaultProvider |
Získá nebo nastaví výchozího zprostředkovatele. |
| DisableExpiration |
Získá nebo nastaví hodnotu určující, zda je vypršení platnosti mezipaměti zakázané. |
| DisableMemoryCollection |
Získá nebo nastaví hodnotu určující, zda je kolekce paměti mezipaměti zakázána. |
| ElementInformation |
Získá ElementInformation objekt, který obsahuje neuzpůsobitelné informace a funkce ConfigurationElement objektu. (Zděděno od ConfigurationElement) |
| ElementProperty |
Získá ConfigurationElementProperty objekt, který představuje ConfigurationElement objekt sám. (Zděděno od ConfigurationElement) |
| EvaluationContext |
Získá objekt ContextInformation pro objekt ConfigurationElement. (Zděděno od ConfigurationElement) |
| HasContext |
Získá hodnotu, která určuje, zda CurrentConfiguration vlastnost je |
| Item[ConfigurationProperty] |
Získá nebo nastaví vlastnost nebo atribut tohoto elementu konfigurace. (Zděděno od ConfigurationElement) |
| Item[String] |
Získá nebo nastaví vlastnost, atribut nebo podřízený prvek tohoto konfiguračního elementu. (Zděděno od ConfigurationElement) |
| LockAllAttributesExcept |
Získá kolekci uzamčených atributů. (Zděděno od ConfigurationElement) |
| LockAllElementsExcept |
Získá kolekci uzamčených prvků. (Zděděno od ConfigurationElement) |
| LockAttributes |
Získá kolekci uzamčených atributů. (Zděděno od ConfigurationElement) |
| LockElements |
Získá kolekci uzamčených prvků. (Zděděno od ConfigurationElement) |
| LockItem |
Získá nebo nastaví hodnotu označující, zda je prvek uzamčen. (Zděděno od ConfigurationElement) |
| PercentagePhysicalMemoryUsedLimit |
Získá nebo nastaví hodnotu označující maximální procento využití virtuální paměti. |
| PrivateBytesLimit |
Získá nebo nastaví hodnotu označující maximální velikost pracovního procesu privátního prostoru. |
| PrivateBytesPollTime |
Získá nebo nastaví hodnotu označující časový interval mezi dotazováním pro využití paměti pracovního procesu. |
| Properties |
Získá kolekci vlastností. (Zděděno od ConfigurationElement) |
| Providers |
Získá kolekci nastavení zprostředkovatele. |
| SectionInformation |
SectionInformation Získá objekt, který obsahuje neuzpůsobitelné informace a funkce objektuConfigurationSection. (Zděděno od ConfigurationSection) |
Metody
| Name | Description |
|---|---|
| DeserializeElement(XmlReader, Boolean) |
Načte XML z konfiguračního souboru. (Zděděno od ConfigurationElement) |
| DeserializeSection(XmlReader) |
Načte XML z konfiguračního souboru. (Zděděno od ConfigurationSection) |
| Equals(Object) |
Porovná aktuální ConfigurationElement instanci se zadaným objektem. (Zděděno od ConfigurationElement) |
| GetHashCode() |
Získá jedinečnou hodnotu představující aktuální ConfigurationElement instanci. (Zděděno od ConfigurationElement) |
| GetRuntimeObject() |
Vrátí vlastní objekt při přepsání v odvozené třídě. (Zděděno od ConfigurationSection) |
| GetTransformedAssemblyString(String) |
Vrátí transformovanou verzi zadaného názvu sestavení. (Zděděno od ConfigurationElement) |
| GetTransformedTypeString(String) |
Vrátí transformovanou verzi zadaného názvu typu. (Zděděno od ConfigurationElement) |
| GetType() |
Získá Type aktuální instance. (Zděděno od Object) |
| Init() |
Nastaví objekt ConfigurationElement na jeho počáteční stav. (Zděděno od ConfigurationElement) |
| InitializeDefault() |
Slouží k inicializaci výchozí sady hodnot pro objekt ConfigurationElement. (Zděděno od ConfigurationElement) |
| IsModified() |
Určuje, zda byl tento konfigurační prvek změněn od posledního uložení nebo načtení při implementaci v odvozené třídě. (Zděděno od ConfigurationSection) |
| IsReadOnly() |
Získá hodnotu určující, zda ConfigurationElement objekt je jen pro čtení. (Zděděno od ConfigurationElement) |
| ListErrors(IList) |
Přidá chyby neplatné vlastnosti v tomto ConfigurationElement objektu a ve všech dílčích poplatcích do předaného seznamu. (Zděděno od ConfigurationElement) |
| MemberwiseClone() |
Vytvoří mělkou kopii aktuálního Object. (Zděděno od Object) |
| OnDeserializeUnrecognizedAttribute(String, String) |
Získá hodnotu určující, zda neznámý atribut je zjištěn během deserializace. (Zděděno od ConfigurationElement) |
| OnDeserializeUnrecognizedElement(String, XmlReader) |
Získá hodnotu určující, zda neznámý prvek je zjištěn během deserializace. (Zděděno od ConfigurationElement) |
| OnRequiredPropertyNotFound(String) |
Vyvolá výjimku, pokud nebyla nalezena požadovaná vlastnost. (Zděděno od ConfigurationElement) |
| PostDeserialize() |
Volal po deserializaci. (Zděděno od ConfigurationElement) |
| PreSerialize(XmlWriter) |
Volá se před serializací. (Zděděno od ConfigurationElement) |
| Reset(ConfigurationElement) |
Obnoví vnitřní stav objektu ConfigurationElement , včetně zámků a kolekcí vlastností. (Zděděno od ConfigurationElement) |
| ResetModified() |
Obnoví hodnotu IsModified() metody na |
| SerializeElement(XmlWriter, Boolean) |
Zapíše obsah tohoto konfiguračního prvku do konfiguračního souboru při implementaci v odvozené třídě. (Zděděno od ConfigurationElement) |
| SerializeSection(ConfigurationElement, String, ConfigurationSaveMode) |
Vytvoří řetězec XML obsahující nerozčleněné zobrazení objektu ConfigurationSection jako jeden oddíl pro zápis do souboru. (Zděděno od ConfigurationSection) |
| SerializeToXmlElement(XmlWriter, String) |
Zapíše vnější značky tohoto konfiguračního prvku do konfiguračního souboru při implementaci v odvozené třídě. (Zděděno od ConfigurationElement) |
| SetPropertyValue(ConfigurationProperty, Object, Boolean) |
Nastaví vlastnost na zadanou hodnotu. (Zděděno od ConfigurationElement) |
| SetReadOnly() |
IsReadOnly() Nastaví vlastnost pro ConfigurationElement objekt a všechny dílčí prvky. (Zděděno od ConfigurationElement) |
| ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName) |
Určuje, zda zadaný prvek má být serializován, když je hierarchie objektu konfigurace serializována pro zadanou cílovou verzi .NET Framework. (Zděděno od ConfigurationSection) |
| ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement) |
Určuje, zda má být zadaná vlastnost serializována, pokud je hierarchie objektu konfigurace serializována pro zadanou cílovou verzi .NET Framework. (Zděděno od ConfigurationSection) |
| ShouldSerializeSectionInTargetVersion(FrameworkName) |
Určuje, zda aktuální ConfigurationSection instance by měla být serializována, pokud je hierarchie objektů konfigurace serializována pro zadanou cílovou verzi .NET Framework. (Zděděno od ConfigurationSection) |
| ToString() |
Vrátí řetězec, který představuje aktuální objekt. (Zděděno od Object) |
| Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode) |
Upraví objekt tak ConfigurationElement , aby odebral všechny hodnoty, které by neměly být uloženy. (Zděděno od ConfigurationElement) |