ControlCachePolicy.SetSlidingExpiration(Boolean) Méthode

Définition

Indique au BasePartialCachingControl contrôle qui encapsule le contrôle utilisateur pour définir l’entrée de cache du contrôle utilisateur pour utiliser l’expiration glissante ou absolue.

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

Paramètres

useSlidingExpiration
Boolean

true pour utiliser l’expiration du cache glissante au lieu de l’expiration absolue ; sinon, false.

Exceptions

Le contrôle utilisateur n’est pas associé à un BasePartialCachingControl contrôle et n’est pas mis en cache.

Exemples

L’exemple de code suivant montre comment un contrôle utilisateur peut être chargé dynamiquement et manipulé par programmation au moment de l’exécution. Un contrôle utilisateur nommé SimpleControl est décoré avec un PartialCachingAttribute attribut, ce qui signifie qu’il est encapsulé par un PartialCachingControl contrôle au moment de l’exécution. Les SimpleControl paramètres de mise en cache de l’objet peuvent être manipulés par programmation via son objet associé ControlCachePolicy , qui est disponible via une référence au PartialCachingControl contrôle qui l’encapsule. Dans cet exemple, les paramètres de mise en cache sont examinés lors de l’initialisation de la page et modifiés si certaines conditions sont remplies. Cet exemple fait partie d’un exemple plus large fourni pour la ControlCachePolicy classe.

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

Remarques

Utilisez les SetExpires méthodes ( SetSlidingExpiration passage true) pour indiquer au BasePartialCachingControl contrôle qui encapsule le contrôle utilisateur pour utiliser une stratégie de mise en cache d’expiration glissante au lieu d’une stratégie d’expiration absolue. Utilisez la méthode et la SetExpiresSetSlidingExpiration méthode (passage false) pour spécifier une stratégie d’expiration absolue.

S’applique à

Voir aussi