CacheSection Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengonfigurasi pengaturan cache global untuk aplikasi ASP.NET. Kelas ini tidak dapat diwariskan.
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
- Warisan
Contoh
Contoh kode berikut menunjukkan halaman dan file kode terkait yang digunakan untuk mengakses CacheSection atribut bagian.
<%@ 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
Keterangan
Kelas ini CacheSection menyediakan cara untuk mengakses dan memodifikasi <cache> bagian file konfigurasi secara terprogram.
Fitur penembolokan ASP.NET diimplementasikan oleh kelas Cache. Untuk informasi selengkapnya, lihat Penembolokan.
Note
CacheSection dapat menulis informasi ke bagian terkait dari file konfigurasi sesuai dengan batasan yang ditentukan oleh properti AllowDefinition bagian yang nilainya adalah MachineToApplication. Setiap upaya untuk menulis dalam file konfigurasi pada tingkat yang tidak diizinkan dalam hierarki akan mengakibatkan pesan kesalahan yang dihasilkan oleh pengurai. Namun, Anda dapat menggunakan kelas ini untuk membaca informasi konfigurasi di tingkat mana pun dalam hierarki.
Cache adalah tabel hash khusus aplikasi yang digunakan untuk menyimpan data yang sering diakses. Status aplikasi dan sesi mirip dengan cache, status aplikasi menjadi yang paling mirip, karena cakupan di seluruh aplikasinya. Salah satu perbedaan terbesar antara cache dan mekanisme status aplikasi adalah bahwa cache mendukung dependensi Dependensi ini memungkinkan untuk membangun aplikasi yang secara otomatis menghapus item yang di-cache ketika peristiwa tertentu terjadi.
Konstruktor
| Nama | Deskripsi |
|---|---|
| CacheSection() |
Menginisialisasi instans baru dari kelas CacheSection. |
Properti
| Nama | Deskripsi |
|---|---|
| CurrentConfiguration |
Mendapatkan referensi ke instans Configuration tingkat atas yang mewakili hierarki konfigurasi tempat instans ConfigurationElement saat ini berada. (Diperoleh dari ConfigurationElement) |
| DefaultProvider |
Mendapatkan atau mengatur penyedia default. |
| DisableExpiration |
Mendapatkan atau menetapkan nilai yang menunjukkan apakah kedaluwarsa cache dinonaktifkan. |
| DisableMemoryCollection |
Mendapatkan atau menetapkan nilai yang menunjukkan apakah kumpulan memori cache dinonaktifkan. |
| ElementInformation |
Mendapatkan objek ElementInformation yang berisi informasi dan fungsionalitas yang tidak dapat disesuaikan dari objek ConfigurationElement. (Diperoleh dari ConfigurationElement) |
| ElementProperty |
Mendapatkan objek ConfigurationElementProperty yang mewakili objek ConfigurationElement itu sendiri. (Diperoleh dari ConfigurationElement) |
| EvaluationContext |
Mendapatkan objek ContextInformation untuk objek ConfigurationElement. (Diperoleh dari ConfigurationElement) |
| HasContext |
Mendapatkan nilai yang menunjukkan apakah properti CurrentConfiguration |
| Item[ConfigurationProperty] |
Mendapatkan atau mengatur properti atau atribut elemen konfigurasi ini. (Diperoleh dari ConfigurationElement) |
| Item[String] |
Mendapatkan atau mengatur properti, atribut, atau elemen turunan dari elemen konfigurasi ini. (Diperoleh dari ConfigurationElement) |
| LockAllAttributesExcept |
Mendapatkan koleksi atribut terkunci. (Diperoleh dari ConfigurationElement) |
| LockAllElementsExcept |
Mendapatkan koleksi elemen terkunci. (Diperoleh dari ConfigurationElement) |
| LockAttributes |
Mendapatkan koleksi atribut terkunci. (Diperoleh dari ConfigurationElement) |
| LockElements |
Mendapatkan koleksi elemen terkunci. (Diperoleh dari ConfigurationElement) |
| LockItem |
Mendapatkan atau menetapkan nilai yang menunjukkan apakah elemen dikunci. (Diperoleh dari ConfigurationElement) |
| PercentagePhysicalMemoryUsedLimit |
Mendapatkan atau menetapkan nilai yang menunjukkan persentase maksimum penggunaan memori virtual. |
| PrivateBytesLimit |
Mendapatkan atau menetapkan nilai yang menunjukkan ukuran maksimum ruang privat proses kerja. |
| PrivateBytesPollTime |
Mendapatkan atau menetapkan nilai yang menunjukkan interval waktu antara polling untuk penggunaan memori proses pekerja. |
| Properties |
Mendapatkan koleksi properti. (Diperoleh dari ConfigurationElement) |
| Providers |
Mendapatkan kumpulan pengaturan penyedia. |
| SectionInformation |
Mendapatkan objek SectionInformation yang berisi informasi dan fungsionalitas yang tidak dapat disesuaikan dari objek ConfigurationSection. (Diperoleh dari ConfigurationSection) |
Metode
| Nama | Deskripsi |
|---|---|
| DeserializeElement(XmlReader, Boolean) |
Membaca XML dari file konfigurasi. (Diperoleh dari ConfigurationElement) |
| DeserializeSection(XmlReader) |
Membaca XML dari file konfigurasi. (Diperoleh dari ConfigurationSection) |
| Equals(Object) |
Membandingkan instans ConfigurationElement saat ini dengan objek yang ditentukan. (Diperoleh dari ConfigurationElement) |
| GetHashCode() |
Mendapatkan nilai unik yang mewakili instans ConfigurationElement saat ini. (Diperoleh dari ConfigurationElement) |
| GetRuntimeObject() |
Mengembalikan objek kustom saat ditimpa di kelas turunan. (Diperoleh dari ConfigurationSection) |
| GetTransformedAssemblyString(String) |
Mengembalikan versi yang diubah dari nama rakitan yang ditentukan. (Diperoleh dari ConfigurationElement) |
| GetTransformedTypeString(String) |
Mengembalikan versi yang diubah dari nama jenis yang ditentukan. (Diperoleh dari ConfigurationElement) |
| GetType() |
Mendapatkan Type instans saat ini. (Diperoleh dari Object) |
| Init() |
Mengatur objek ConfigurationElement ke status awalnya. (Diperoleh dari ConfigurationElement) |
| InitializeDefault() |
Digunakan untuk menginisialisasi sekumpulan nilai default untuk objek ConfigurationElement. (Diperoleh dari ConfigurationElement) |
| IsModified() |
Menunjukkan apakah elemen konfigurasi ini telah dimodifikasi sejak terakhir disimpan atau dimuat saat diimplementasikan di kelas turunan. (Diperoleh dari ConfigurationSection) |
| IsReadOnly() |
Mendapatkan nilai yang menunjukkan apakah objek ConfigurationElement bersifat baca-saja. (Diperoleh dari ConfigurationElement) |
| ListErrors(IList) |
Menambahkan kesalahan properti yang tidak valid dalam objek ConfigurationElement ini, dan di semua subelemen, ke daftar yang diteruskan. (Diperoleh dari ConfigurationElement) |
| MemberwiseClone() |
Membuat salinan dangkal dari Objectsaat ini. (Diperoleh dari Object) |
| OnDeserializeUnrecognizedAttribute(String, String) |
Mendapatkan nilai yang menunjukkan apakah atribut yang tidak diketahui ditemui selama deserialisasi. (Diperoleh dari ConfigurationElement) |
| OnDeserializeUnrecognizedElement(String, XmlReader) |
Mendapatkan nilai yang menunjukkan apakah elemen yang tidak diketahui ditemui selama deserialisasi. (Diperoleh dari ConfigurationElement) |
| OnRequiredPropertyNotFound(String) |
Melempar pengecualian ketika properti yang diperlukan tidak ditemukan. (Diperoleh dari ConfigurationElement) |
| PostDeserialize() |
Dipanggil setelah deserialisasi. (Diperoleh dari ConfigurationElement) |
| PreSerialize(XmlWriter) |
Dipanggil sebelum serialisasi. (Diperoleh dari ConfigurationElement) |
| Reset(ConfigurationElement) |
Mereset status internal objek ConfigurationElement, termasuk kunci dan koleksi properti. (Diperoleh dari ConfigurationElement) |
| ResetModified() |
Mengatur ulang nilai metode IsModified() ke |
| SerializeElement(XmlWriter, Boolean) |
Menulis konten elemen konfigurasi ini ke file konfigurasi saat diimplementasikan di kelas turunan. (Diperoleh dari ConfigurationElement) |
| SerializeSection(ConfigurationElement, String, ConfigurationSaveMode) |
Membuat string XML yang berisi tampilan objek ConfigurationSection yang tidak digabungkan sebagai satu bagian untuk ditulis ke file. (Diperoleh dari ConfigurationSection) |
| SerializeToXmlElement(XmlWriter, String) |
Menulis tag luar elemen konfigurasi ini ke file konfigurasi saat diimplementasikan di kelas turunan. (Diperoleh dari ConfigurationElement) |
| SetPropertyValue(ConfigurationProperty, Object, Boolean) |
Mengatur properti ke nilai yang ditentukan. (Diperoleh dari ConfigurationElement) |
| SetReadOnly() |
Mengatur properti IsReadOnly() untuk objek ConfigurationElement dan semua subelemen. (Diperoleh dari ConfigurationElement) |
| ShouldSerializeElementInTargetVersion(ConfigurationElement, String, FrameworkName) |
Menunjukkan apakah elemen yang ditentukan harus diserialisasikan ketika hierarki objek konfigurasi diserialisasikan untuk versi target yang ditentukan dari .NET Framework. (Diperoleh dari ConfigurationSection) |
| ShouldSerializePropertyInTargetVersion(ConfigurationProperty, String, FrameworkName, ConfigurationElement) |
Menunjukkan apakah properti yang ditentukan harus diserialisasikan ketika hierarki objek konfigurasi diserialisasikan untuk versi target yang ditentukan dari .NET Framework. (Diperoleh dari ConfigurationSection) |
| ShouldSerializeSectionInTargetVersion(FrameworkName) |
Menunjukkan apakah instans ConfigurationSection saat ini harus diserialisasikan ketika hierarki objek konfigurasi diserialisasikan untuk versi target yang ditentukan dari .NET Framework. (Diperoleh dari ConfigurationSection) |
| ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |
| Unmerge(ConfigurationElement, ConfigurationElement, ConfigurationSaveMode) |
Memodifikasi objek ConfigurationElement untuk menghapus semua nilai yang tidak boleh disimpan. (Diperoleh dari ConfigurationElement) |