프로그래밍/Web Program
Substitution
개발생각11
2020. 2. 24. 22:55
반응형
Substitution (캐시 후 대체)
캐시된 페이지 내 동적으로 컨텐츠를 출력할 때 사용한다.
즉, 전체 페이지를 OutputCache를 이용하여 캐시가 처리되었을 때,
Substitutio 컨트롤은 동적으로 컨텐츠를 출력할 수 있도록 해준다.
간단한 예제를 확인해보면 아래와 같다.
1. Output Cache 하단의 시간은 캐시가 30초간 걸린 시간
2. Substitution 하단의 시간은 <asp:Substitution> 컨트롤을 이용하여 동적으로 현재 시간을 출력 처리한 결과
-> 해당 페이지를 새로 고침 하면 output Cache는 캐시가 걸려 시간이 10:41:10으로 고정되어 있는 반면
Substitution은 새로고침 할 때마다 시간이 새롭게 갱신되는 것을 볼 수 있다.
<h2>OutputCache</h2>
<div><%=test %></div>
<h2>Substitution</h2>
<asp:Substitution runat="server" MethodName="GetCurrentDate" id="substitution" />
#region [ Substitution 메소드 처리 ]
protected static string GetCurrentDate(HttpContext context)
{
return DateTime.Now.ToString();
}
#endregion
반응형