ControlCachePolicy.SetSlidingExpiration(Boolean) Methode

Definitie

Hiermee wordt het BasePartialCachingControl besturingselement geïnstrueerd dat het besturingselement van de gebruiker verpakt om de cachevermelding van het gebruikersbeheer in te stellen voor het gebruik van een schuif- of absolute vervaldatum.

public:
 void SetSlidingExpiration(bool useSlidingExpiration);
public void SetSlidingExpiration(bool useSlidingExpiration);
member this.SetSlidingExpiration : bool -> unit
Public Sub SetSlidingExpiration (useSlidingExpiration As Boolean)

Parameters

useSlidingExpiration
Boolean

true om verlooptijd van de schuifcache te gebruiken in plaats van absolute vervaldatum; anders, false.

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. Een gebruikersbeheer met de naam SimpleControl is ingericht met een PartialCachingAttribute kenmerk, wat betekent dat het 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 worden cache-instellingen onderzocht tijdens de initialisatie van pagina's en gewijzigd 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