Share via


ControlCachePolicy.Duration 속성

정의

출력 캐시에 캐시된 항목을 보관해야 하는 기간을 가져오거나 설정합니다.

public:
 property TimeSpan Duration { TimeSpan get(); void set(TimeSpan value); };
public TimeSpan Duration { get; set; }
member this.Duration : TimeSpan with get, set
Public Property Duration As TimeSpan

속성 값

사용자 정의 컨트롤을 출력 캐시에 보관할 시간(초)을 나타내는 TimeSpan입니다. 기본값은 Zero입니다.

예외

사용자 정의 컨트롤이 BasePartialCachingControl과 연결되어 있지 않아 캐시할 수 없는 경우

또는

Duration 속성이 컨트롤의 초기화 및 렌더링 단계가 아닌 다른 단계에서 설정된 경우

예제

다음 코드 예제에는 사용자 정의 컨트롤 수 동적으로 로드 및 런타임에 프로그래밍 방식으로 조작 하는 방법을 보여 줍니다. PartialCachingAttribute 특성이 라는 사용자 정의 컨트롤에 적용 되 SimpleControl, 즉 래핑되는 PartialCachingControl 런타임 시 컨트롤입니다. SimpleControl 개체의 캐싱 설정을 프로그래밍 방식으로 수 해당 연결을 통해 조작 ControlCachePolicy 개체에 대 한 참조를 통해 제공 되는 PartialCachingControl 를 래핑하는 컨트롤입니다. 이 예제는 Duration 페이지 초기화 하는 동안 속성을 검사 하 고 일부 조건이 충족 될 경우 캐시 만료를 변경 합니다. 이 예제는에 대해 제공 된 큰 예제의 일부는 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>

설명

절대 만료 정책을 사용 하 여 설정 된 경우는 SetSlidingExpiration 메서드는 Duration 속성 캐시 엔트리가 만료 될 때까지 남은 시간을 반환 합니다.

적용 대상

추가 정보