Share via


CacheSection Třída

Definice

Konfiguruje globální nastavení mezipaměti pro aplikaci ASP.NET. Tuto třídu nelze 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 k oddílu <cache> konfiguračního souboru a upravovat ho.

Funkce ASP.NET ukládání do mezipaměti je implementována Cache třídou. Další informace najdete v tématu Ukládání do mezipaměti.

Poznámka

Může CacheSection zapisovat informace do související části konfiguračního souboru podle omezení definovaných vlastností AllowDefinition section, jejíž hodnota je MachineToApplication. Jakýkoli pokus o zápis do konfiguračního souboru na úrovni, která není v hierarchii povolená, způsobí chybovou zprávu vygenerovanou 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á slouží k ukládání často používaných dat. Stav aplikace a relace jsou podobné mezipaměti. Stav aplikace je nejpodobnější vzhledem k rozsahu celé aplikace. Jedním z největších rozdílů mezi mezipamětí a mechanismem stavu aplikace je to, že mezipaměť podporuje závislosti. Tyto závislosti umožňují vytvářet aplikace, které automaticky odeberou položky v mezipaměti, když dojde k určitým událostem.

Konstruktory

CacheSection()

Inicializuje novou instanci CacheSection třídy.

Vlastnosti

CurrentConfiguration

Získá odkaz na instanci nejvyšší úrovně Configuration , která představuje hierarchii konfigurace, do které aktuální ConfigurationElement instance patří.

(Zděděno od ConfigurationElement)
DefaultProvider

Získá nebo nastaví výchozího zprostředkovatele.

DisableExpiration

Získá nebo nastaví hodnotu označující, zda je vypršení platnosti mezipaměti zakázáno.

DisableMemoryCollection

Získá nebo nastaví hodnotu označující, zda je kolekce paměti mezipaměti zakázána.

ElementInformation

Získá ElementInformation objekt, který obsahuje přizpůsobitelné informace a funkce objektu ConfigurationElement .

(Zděděno od ConfigurationElement)
ElementProperty

ConfigurationElementProperty Získá objekt, který představuje ConfigurationElement samotný objekt.

(Zděděno od ConfigurationElement)
EvaluationContext

ContextInformation Získá objekt pro ConfigurationElement objekt.

(Zděděno od ConfigurationElement)
HasContext

Získá hodnotu, která označuje, zda CurrentConfiguration je nullvlastnost .

(Zděděno od ConfigurationElement)
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 elementu konfigurace.

(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 soukromého prostoru pracovního procesu.

PrivateBytesPollTime

Získá nebo nastaví hodnotu označující časový interval mezi dotazováním na 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

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á aktuální Type instanci.

(Zděděno od Object)
Init()

ConfigurationElement Nastaví objekt do počátečního stavu.

(Zděděno od ConfigurationElement)
InitializeDefault()

Slouží k inicializaci výchozí sady hodnot objektu 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 označující, zda ConfigurationElement objekt je jen pro čtení.

(Zděděno od ConfigurationElement)
ListErrors(IList)

Přidá do předaného seznamu chyby neplatné vlastnosti v tomto ConfigurationElement objektu a ve všech dílčích pomůcecích.

(Zděděno od ConfigurationElement)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
OnDeserializeUnrecognizedAttribute(String, String)

Získá hodnotu označující, zda je zjištěn neznámý atribut během deserializace.

(Zděděno od ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

Získá hodnotu označující, zda neznámý prvek je nalezen během deserializace.

(Zděděno od ConfigurationElement)
OnRequiredPropertyNotFound(String)

Vyvolá výjimku, pokud není nalezena požadovaná vlastnost.

(Zděděno od ConfigurationElement)
PostDeserialize()

Volá se po deserializaci.

(Zděděno od ConfigurationElement)
PreSerialize(XmlWriter)

Volá se před serializací.

(Zděděno od ConfigurationElement)
Reset(ConfigurationElement)

Resetuje vnitřní stav objektu ConfigurationElement , včetně zámků a kolekcí vlastností.

(Zděděno od ConfigurationElement)
ResetModified()

Resetuje hodnotu IsModified() metody na false při implementaci v odvozené třídě.

(Zděděno od ConfigurationSection)
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í nesloučené 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 elementu konfigurace 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 objektu ConfigurationElement a všech dílčích elementů.

(Zděděno od ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

Určuje, zda zadaný prvek má být serializován, když je hierarchie objektů konfigurace serializována pro zadanou cílovou verzi rozhraní .NET Framework.

(Zděděno od ConfigurationSection)
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

Určuje, zda má být zadaná vlastnost serializována, když je hierarchie objektů konfigurace serializována pro zadanou cílovou verzi rozhraní .NET Framework.

(Zděděno od ConfigurationSection)
ShouldSerializeSectionInTargetVersion(FrameworkName)

Určuje, zda aktuální ConfigurationSection instance by měla být serializována při hierarchii objektů konfigurace je serializována pro zadanou cílovou verzi rozhraní .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)

Platí pro

Viz také