ControlCachePolicy.SetSlidingExpiration(Boolean) Metódus
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.
Utasítja a BasePartialCachingControl felhasználói vezérlőt burkoló vezérlőt, hogy állítsa be a felhasználói vezérlő gyorsítótár-bejegyzését a csúszás vagy az abszolút lejárat használatára.
public:
void SetSlidingExpiration(bool useSlidingExpiration);
public void SetSlidingExpiration(bool useSlidingExpiration);
member this.SetSlidingExpiration : bool -> unit
Public Sub SetSlidingExpiration (useSlidingExpiration As Boolean)
Paraméterek
- useSlidingExpiration
- Boolean
truetológyorsítótár lejáratának használata az abszolút lejárat helyett; egyéb esetben. false
Kivételek
A felhasználói vezérlő nincs társítva és BasePartialCachingControl nem gyorsítótárazható.
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. A névvel ellátott SimpleControl felhasználói vezérlők attribútummal PartialCachingAttribute lesznek díszítve, 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 gyorsítótárazási beállításokat a lap inicializálása során vizsgáljuk meg, és bizonyos feltételek teljesülése esetén módosulnak. 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
Az és a SetExpires metódusok (átadásSetSlidingExpiration) használatával utasíthatja a true felhasználói vezérlőt burkoló vezérlőt, hogy az abszolút lejárati szabályzat helyett egy csúsztatásos lejárati gyorsítótárazási szabályzatot használjonBasePartialCachingControl.
SetExpires A metódus és a SetSlidingExpiration metódus (átadásfalse) használatával adjon meg egy abszolút lejárati szabályzatot.