Nyelv

ControlCachePolicy.SetExpires(DateTime) Metódus

Definíció

Utasítja a BasePartialCachingControl felhasználói vezérlőt burkoló vezérlőt, hogy a gyorsítótár-bejegyzés a megadott időpontban és időpontban lejárjon.

public:
 void SetExpires(DateTime expirationTime);
public void SetExpires(DateTime expirationTime);
member this.SetExpires : DateTime -> unit
Public Sub SetExpires (expirationTime As DateTime)

Paraméterek

expirationTime
DateTime

Egy DateTime , amely után a gyorsítótárazott bejegyzés lejár.

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. Az PartialCachingAttribute attribútum egy felhasználó által elnevezett SimpleControlvezérlőelemre lesz alkalmazva, ami azt jelenti, hogy a felhasználói vezérlőt futtatáskor egy PartialCachingControl vezérlő burkolta be. 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 tulajdonságot a Duration lap inicializálása során vizsgáljuk meg, és bizonyos feltételek teljesülése esetén a metódusok és SetSlidingExpiration a SetExpires metódusok használatával módosítjuk. 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.

A következőre érvényes:

Lásd még