ControlCachePolicy.Duration Tulajdonság
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Lekéri vagy beállítja, hogy a gyorsítótárazott elemek mennyi ideig maradjanak a kimeneti gyorsítótárban.
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
Tulajdonság értéke
Ez TimeSpan azt az időtartamot jelöli, amellyel a felhasználói vezérlők a kimeneti gyorsítótárban maradnak. Az alapértelmezett érték a Zero.
Kivételek
A felhasználói vezérlő nincs társítva és BasePartialCachingControl nem gyorsítótárazható.
-vagy-
A Duration tulajdonság a vezérlő inicializálási és renderelési szakaszain kívül van beállítva.
Példák
Az alábbi példakód bemutatja, hogyan tölthető be egy felhasználói vezérlő dinamikusan és programozottan futtatáskor. Az PartialCachingAttribute attribútum egy felhasználó által elnevezett SimpleControlvezérlőelemre lesz alkalmazva, ami azt jelenti, hogy futtatáskor egy PartialCachingControl vezérlő burkolja. Az SimpleControl objektum gyorsítótárazási beállításai programozott módon módosíthatók a társított ControlCachePolicy objektumon keresztül, amely a PartialCachingControl burkoló vezérlőelemre való hivatkozással érhető el. Ebben a példában a rendszer megvizsgálja a tulajdonságot az Duration oldal inicializálása során, és bizonyos feltételek teljesülése esetén a gyorsítótár lejárata megváltozik. Ez a példa egy nagyobb, az ControlCachePolicy osztályhoz tartozó példa része.
<%@ 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>
Megjegyzések
Ha az abszolút lejárati szabályzatot a SetSlidingExpiration metódussal állítja be, a tulajdonság a Duration gyorsítótárbejegyzés lejáratáig fennmaradó időt adja vissza.