ControlCachePolicy.Duration Properti
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.
Mendapatkan atau mengatur jumlah waktu item yang di-cache akan tetap berada di cache output.
public:
property TimeSpan Duration { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan Duration { get; set; }
member this.Duration : TimeSpan with get, set
Public Property Duration As TimeSpan
Nilai Properti
TimeSpan yang menunjukkan jumlah waktu kontrol pengguna adalah tetap berada di cache output. Default adalah Zero.
Pengecualian
Kontrol pengguna tidak terkait dengan BasePartialCachingControl dan tidak dapat di-cache.
-atau-
Properti Duration diatur di luar tahap inisialisasi dan penyajian kontrol.
Contoh
Contoh kode berikut menunjukkan bagaimana kontrol pengguna dapat dimuat secara dinamis dan dimanipulasi secara terprogram pada durasi. Atribut PartialCachingAttribute diterapkan ke kontrol pengguna bernama SimpleControl
, yang berarti dibungkus oleh PartialCachingControl kontrol pada durasi. Pengaturan SimpleControl
penembolokan objek dapat dimanipulasi secara terprogram melalui objek terkait ControlCachePolicy , yang tersedia melalui referensi ke PartialCachingControl kontrol yang membungkusnya. Dalam contoh ini, properti diperiksa selama inisialisasi halaman dan kedaluwarsa Duration cache diubah jika beberapa kondisi terpenuhi. Contoh ini adalah bagian dari contoh yang lebih besar yang disediakan untuk ControlCachePolicy kelas .
<%@ Page Language="C#" %>
<%@ Reference Control="SimpleControl.ascx" %>
<script language="C#" runat="server">
// The following example demonstrates how to load a user control dynamically at run time, and
// work with the ControlCachePolicy object associated with it.
// Loads and displays a UserControl defined in a seperate Logonform.ascx file.
// You need to have "SimpleControl.ascx" file in
// the same directory as the aspx file.
void Page_Init(object sender, System.EventArgs e) {
// Obtain a PartialCachingControl object which wraps the 'LogOnControl' user control.
PartialCachingControl pcc = LoadControl("SimpleControl.ascx") as PartialCachingControl;
// If the control is slated to expire in greater than 60 Seconds
if (pcc.CachePolicy.Duration > TimeSpan.FromSeconds(60) )
{
// Make it expire faster. Set a new expiration time to 30 seconds, and make it
// an absolute expiration if it isnt already.
pcc.CachePolicy.SetExpires(DateTime.Now.Add(TimeSpan.FromSeconds(30)));
pcc.CachePolicy.SetSlidingExpiration(false);
}
Controls.Add(pcc);
}
</script>
<%@ Page Language="VB" %>
<%@ Reference Control="SimpleControl.ascx" %>
<script language="VB" runat="server">
' The following example demonstrates how to load a user control dynamically at run time, and
' work with the ControlCachePolicy object associated with it.
' Loads and displays a UserControl defined in a seperate Logonform.ascx file.
' You need to have "SimpleControl.ascx" file in
' the same directory as the aspx file.
Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
' Obtain a PartialCachingControl object which wraps the 'LogOnControl' user control.
Dim pcc As PartialCachingControl
pcc = LoadControl("SimpleControl.ascx")
' If the control is slated to expire in greater than 60 Seconds
If (pcc.CachePolicy.Duration > TimeSpan.FromSeconds(60)) Then
' Make it expire faster. Set a new expiration time to 30 seconds, and make it
' an absolute expiration if it isnt already.
pcc.CachePolicy.SetExpires(DateTime.Now.Add(TimeSpan.FromSeconds(30)))
pcc.CachePolicy.SetSlidingExpiration(False)
End If
Controls.Add(pcc)
End Sub
</script>
Keterangan
Jika kebijakan kedaluwarsa absolut diatur menggunakan SetSlidingExpiration metode , Duration properti mengembalikan jumlah waktu yang tersisa sampai entri cache kedaluwarsa.