ControlCachePolicy.SetExpires(DateTime) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
BasePartialCachingControl 지정된 날짜 및 시간에 캐시 항목을 만료하도록 사용자 컨트롤을 래핑하는 컨트롤에 지시합니다.
public:
void SetExpires(DateTime expirationTime);
public void SetExpires(DateTime expirationTime);
member this.SetExpires : DateTime -> unit
Public Sub SetExpires (expirationTime As DateTime)
매개 변수
예외
사용자 컨트롤은 a BasePartialCachingControl 와 연결되지 않으며 캐시할 수 없습니다.
예제
다음 코드 예제에서는 사용자 컨트롤을 동적으로 로드 하 고 런타임에 프로그래밍 방식으로 조작할 수 있는 방법을 보여 줍니다.
PartialCachingAttribute 이 특성은 명명SimpleControl된 사용자 컨트롤에 적용됩니다. 즉, 사용자 컨트롤은 런타임에 컨트롤에 PartialCachingControl 의해 래핑됩니다. 개체의 캐싱 설정은 SimpleControl 연결된 ControlCachePolicy 개체를 통해 프로그래밍 방식으로 조작할 수 있으며 이를 래핑하는 컨트롤에 PartialCachingControl 대한 참조를 통해 사용할 수 있습니다. 이 예제 Duration 에서 속성은 페이지 초기화 중에 검사되고 일부 조건이 충족되는 경우 및 SetExpires 메서드를 사용하여 SetSlidingExpiration 변경됩니다. 이 예제는 클래스에 제공된 더 큰 예제의 ControlCachePolicy 일부입니다.
<%@ 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>
설명
SetExpires
SetSlidingExpiration 및 메서드(전달true)를 사용하여 절대 만료 정책 대신 슬라이딩 만료 캐싱 정책을 사용하도록 사용자 컨트롤을 래핑하는 컨트롤에 지시 BasePartialCachingControl 합니다.
SetExpires 메서드와 SetSlidingExpiration 메서드(전달false)를 사용하여 절대 만료 정책을 지정합니다.