ControlCachePolicy.SetExpires(DateTime) Methode

Definitie

Hiermee wordt het BasePartialCachingControl besturingselement geïnstrueerd dat het besturingselement van de gebruiker de cachevermelding op de opgegeven datum en tijd laat verlopen.

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

Parameters

expirationTime
DateTime

Een DateTime waarna de vermelding in de cache verloopt.

Uitzonderingen

Het gebruikersbeheer is niet gekoppeld aan een BasePartialCachingControl en kan niet in de cache worden opgeslagen.

Voorbeelden

In het volgende codevoorbeeld ziet u hoe een gebruikersbeheer dynamisch kan worden geladen en programmatisch kan worden gemanipuleerd tijdens runtime. Het PartialCachingAttribute kenmerk wordt toegepast op een gebruikersbeheer met de naam SimpleControl, wat betekent dat het gebruikersbeheer wordt verpakt door een PartialCachingControl besturingselement tijdens runtime. De cache-instellingen van het SimpleControl object kunnen programmatisch worden bewerkt via het bijbehorende ControlCachePolicy object, dat beschikbaar is via een verwijzing naar het PartialCachingControl besturingselement waarmee het wordt verpakt. In dit voorbeeld wordt de eigenschap onderzocht tijdens de initialisatie van de Duration pagina en gewijzigd met behulp van de SetSlidingExpiration en SetExpires methoden als aan bepaalde voorwaarden wordt voldaan. Dit voorbeeld maakt deel uit van een groter voorbeeld voor de ControlCachePolicy klasse.

<%@ 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>

Opmerkingen

Gebruik de SetExpires en SetSlidingExpiration methoden (doorgeven true) om het BasePartialCachingControl besturingselement te instrueren dat het gebruikersbeheer verpakt om een glijdend verloopcachebeleid te gebruiken in plaats van een absoluut verloopbeleid. Gebruik de SetExpires methode en de SetSlidingExpiration methode (doorgeven false) om een absoluut verloopbeleid op te geven.

Van toepassing op

Zie ook