ControlCachePolicy.SetExpires(DateTime) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Instrui o BasePartialCachingControl controlo que envolve o controlo do utilizador a expirar a entrada da cache na data e hora especificadas.
public:
void SetExpires(DateTime expirationTime);
public void SetExpires(DateTime expirationTime);
member this.SetExpires : DateTime -> unit
Public Sub SetExpires (expirationTime As DateTime)
Parâmetros
Exceções
O controlo do utilizador não está associado a um BasePartialCachingControl e não é cacheável.
Exemplos
O exemplo de código seguinte demonstra como um controlo do utilizador pode ser carregado dinamicamente e manipulado programaticamente em tempo de execução. O PartialCachingAttribute atributo é aplicado a um controlo de utilizador chamado SimpleControl, o que significa que o controlo de utilizador é envolto por um PartialCachingControl controlo em tempo de execução. As SimpleControl definições de cache do objeto podem ser manipuladas programaticamente através do objeto associado ControlCachePolicy , que está disponível através de uma referência ao PartialCachingControl controlo que o envolve. Neste exemplo, a Duration propriedade é examinada durante a inicialização da página e alterada usando os SetSlidingExpiration métodos e SetExpires se algumas condições forem cumpridas. Este exemplo faz parte de um exemplo mais amplo fornecido à ControlCachePolicy turma.
<%@ 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>
Observações
Use os SetExpires métodos e SetSlidingExpiration (passing true) para instruir o BasePartialCachingControl controlo que envolve o controlo do utilizador a usar uma política de cache de expiração deslizante em vez de uma política de expiração absoluta. Use o SetExpires método e o SetSlidingExpiration método (passo false) para especificar uma política de expiração absoluta.