CacheSection クラス

定義

ASP.NET アプリケーションのグローバル キャッシュ設定を構成します。 このクラスは継承できません。

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
継承

次のコード例は、セクション属性へのアクセスに使用されるページと関連するコード ファイルを 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

注釈

CacheSection クラスを使用すると、構成ファイルの <cache> セクションにプログラムからアクセスして変更できます。

ASP.NET キャッシュ機能は、クラスによってCache実装されます。 詳細については、「 キャッシュ」を参照してください。

注意

構成CacheSectionファイルの関連セクションに情報を書き込むには、値MachineToApplicationが のセクション プロパティAllowDefinitionで定義されている制限に従います。 階層内で許可されていないレベルで構成ファイルに書き込もうとすると、パーサーによってエラー メッセージが生成されます。 ただし、このクラスを使用して、階層内の任意のレベルで構成情報を読み取ることができます。

キャッシュは、頻繁にアクセスされるデータを格納するために使用されるアプリケーション固有のハッシュ テーブルです。 アプリケーションとセッションの状態はキャッシュに似ています。アプリケーション全体のスコープにより、アプリケーションの状態が最も似ています。 キャッシュとアプリケーション状態メカニズムの最大の違いの 1 つは、キャッシュが依存関係をサポートしていることです。これらの依存関係により、特定のイベントが発生したときにキャッシュされた項目を自動的に削除するアプリケーションを構築できます。

コンストラクター

CacheSection()

CacheSection クラスの新しいインスタンスを初期化します。

プロパティ

CurrentConfiguration

現在の Configuration インスタンスが属している構成階層を表す最上位の ConfigurationElement インスタンスへの参照を取得します。

(継承元 ConfigurationElement)
DefaultProvider

既定のプロバイダーを取得または設定します。

DisableExpiration

キャッシュの有効期限が無効かどうかを示す値を取得または設定します。

DisableMemoryCollection

キャッシュ メモリ コレクションが無効かどうかを示す値を取得または設定します。

ElementInformation

ElementInformation オブジェクトのカスタマイズできない情報と機能を格納する ConfigurationElement オブジェクトを取得します。

(継承元 ConfigurationElement)
ElementProperty

ConfigurationElementProperty オブジェクト自体を表す ConfigurationElement オブジェクトを取得します。

(継承元 ConfigurationElement)
EvaluationContext

ContextInformation オブジェクトの ConfigurationElement オブジェクトを取得します。

(継承元 ConfigurationElement)
HasContext

CurrentConfiguration プロパティが null であるかどうかを示す値を取得します。

(継承元 ConfigurationElement)
Item[ConfigurationProperty]

この構成要素のプロパティまたは属性を取得または設定します。

(継承元 ConfigurationElement)
Item[String]

この構成要素のプロパティ、属性、または子要素を取得または設定します。

(継承元 ConfigurationElement)
LockAllAttributesExcept

ロックされている属性のコレクションを取得します。

(継承元 ConfigurationElement)
LockAllElementsExcept

ロックされている要素のコレクションを取得します。

(継承元 ConfigurationElement)
LockAttributes

ロックされている属性のコレクションを取得します。

(継承元 ConfigurationElement)
LockElements

ロックされている要素のコレクションを取得します。

(継承元 ConfigurationElement)
LockItem

要素がロックされているかどうかを示す値を取得または設定します。

(継承元 ConfigurationElement)
PercentagePhysicalMemoryUsedLimit

仮想メモリの最大使用率を示す値を取得または設定します。

PrivateBytesLimit

ワーカー プロセスの専用領域の最大サイズを示す値を取得または設定します。

PrivateBytesPollTime

ワーカー プロセス メモリの使用状況を調べるためのポーリングの間隔を示す値を取得または設定します。

Properties

プロパティのコレクションを取得します。

(継承元 ConfigurationElement)
Providers

プロバイダーの設定のコレクションを取得します。

SectionInformation

SectionInformation オブジェクトのカスタマイズできない情報と機能を格納する ConfigurationSection オブジェクトを取得します。

(継承元 ConfigurationSection)

メソッド

DeserializeElement(XmlReader, Boolean)

構成ファイルから XML を読み取ります。

(継承元 ConfigurationElement)
DeserializeSection(XmlReader)

構成ファイルから XML を読み取ります。

(継承元 ConfigurationSection)
Equals(Object)

現在の ConfigurationElement インスタンスを、指定したオブジェクトと比較します。

(継承元 ConfigurationElement)
GetHashCode()

現在の ConfigurationElement インスタンスを表す一意の値を取得します。

(継承元 ConfigurationElement)
GetRuntimeObject()

派生クラスでオーバーライドされると、カスタム オブジェクトを返します。

(継承元 ConfigurationSection)
GetTransformedAssemblyString(String)

指定されたアセンブリ名を変換して返します。

(継承元 ConfigurationElement)
GetTransformedTypeString(String)

指定された型名を変換して返します。

(継承元 ConfigurationElement)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
Init()

ConfigurationElement オブジェクトを初期状態に設定します。

(継承元 ConfigurationElement)
InitializeDefault()

ConfigurationElement オブジェクトの既定の値セットを初期化するために使用します。

(継承元 ConfigurationElement)
IsModified()

派生クラスに実装された場合、この構成要素が最後の保存または読み込み以降に変更されたかどうかを示します。

(継承元 ConfigurationSection)
IsReadOnly()

ConfigurationElement オブジェクトが読み取り専用かどうかを示す値を取得します。

(継承元 ConfigurationElement)
ListErrors(IList)

この ConfigurationElement オブジェクトおよびすべてのサブ要素の無効なプロパティのエラーを、渡されたリストに追加します。

(継承元 ConfigurationElement)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
OnDeserializeUnrecognizedAttribute(String, String)

逆シリカル化中に不明な属性が発生したかどうかを示す値を取得します。

(継承元 ConfigurationElement)
OnDeserializeUnrecognizedElement(String, XmlReader)

逆シリカル化中に不明な要素が発生したかどうかを示す値を取得します。

(継承元 ConfigurationElement)
OnRequiredPropertyNotFound(String)

必要なプロパティが見つからないと例外がスローされます。

(継承元 ConfigurationElement)
PostDeserialize()

逆シリアル化後に呼び出されます。

(継承元 ConfigurationElement)
PreSerialize(XmlWriter)

シリアル化前に呼び出されます。

(継承元 ConfigurationElement)
Reset(ConfigurationElement)

ConfigurationElement オブジェクトの内部状態 (ロックやプロパティ コレクションなど) をリセットします。

(継承元 ConfigurationElement)
ResetModified()

IsModified() メソッドの値が派生クラスに実装されたときに、false にリセットします。

(継承元 ConfigurationSection)
SerializeElement(XmlWriter, Boolean)

派生クラスに実装されている場合、この構成要素の内容を構成ファイルに書き込みます。

(継承元 ConfigurationElement)
SerializeSection(ConfigurationElement, String, ConfigurationSaveMode)

ファイルに書き込む 1 つのセクションとして、ConfigurationSection オブジェクトのアンマージされたビューを含む XML 文字列を作成します。

(継承元 ConfigurationSection)
SerializeToXmlElement(XmlWriter, String)

派生クラスに実装されている場合、この構成要素の外側のタグを構成ファイルに書き込みます。

(継承元 ConfigurationElement)
SetPropertyValue(ConfigurationProperty, Object, Boolean)

プロパティを指定した値に設定します。

(継承元 ConfigurationElement)
SetReadOnly()

IsReadOnly() オブジェクトおよびすべてのサブ要素に ConfigurationElement プロパティを設定します。

(継承元 ConfigurationElement)
ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName)

指定したターゲット バージョンの.NET Frameworkの構成オブジェクト階層をシリアル化するときに、指定した要素をシリアル化する必要があるかどうかを示します。

(継承元 ConfigurationSection)
ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement)

指定したターゲット バージョンの.NET Frameworkの構成オブジェクト階層をシリアル化するときに、指定したプロパティをシリアル化するかどうかを示します。

(継承元 ConfigurationSection)
ShouldSerializeSectionInTargetVersion(FrameworkName)

指定したターゲット バージョンの.NET Frameworkに対して構成オブジェクト階層をシリアル化するときに、現在ConfigurationSectionのインスタンスをシリアル化する必要があるかどうかを示します。

(継承元 ConfigurationSection)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)
Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode)

保存しないすべての値を削除するには、ConfigurationElement オブジェクトを変更します。

(継承元 ConfigurationElement)

適用対象

こちらもご覧ください