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