HttpResponse.AddCacheDependency(CacheDependency[]) 메서드

정의

응답이 출력 캐시에 저장되어 있는 상태에서 지정된 종속성이 변경될 때 보다 편리하게 응답을 무효화할 수 있도록 캐시 종속성 집합을 응답에 연결합니다.

public:
 void AddCacheDependency(... cli::array <System::Web::Caching::CacheDependency ^> ^ dependencies);
public void AddCacheDependency (params System.Web.Caching.CacheDependency[] dependencies);
member this.AddCacheDependency : System.Web.Caching.CacheDependency[] -> unit
Public Sub AddCacheDependency (ParamArray dependencies As CacheDependency())

매개 변수

dependencies
CacheDependency[]

애플리케이션 종속성 목록에 추가할 파일, 캐시 키 또는 CacheDependency입니다.

예외

dependencies 매개 변수가 null인 경우

이 메서드는 캐시된 응답이 이미 만들어진 후 캐시 처리 파이프라인에서 너무 늦게 호출되었습니다.

예제

다음 예제에서는 메서드 및 CacheDependency 개체를 사용하여 AddCacheDependency 캐시 종속성을 만드는 방법을 보여 줍니다.

<%@ Page Language="C#" %>
<%@ outputcache duration="30" varybyparam="none" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="Server">
    private void Page_Load(object sender, System.EventArgs e)
    {
        // Create a Cache Dependency 
        // using a CacheDependency object.
        CacheDependency authorsDependency = new CacheDependency("authors.xml");


        // Make the page invalid if either of the
        // cached items change or expire.        
        Response.AddCacheDependency(authorsDependency);

        // Display the current time for cache reference
        lblOutputCacheMsg.Text = DateTime.Now.ToString();
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Cache Dependencies</title> 
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <table>
            <tbody>
                <tr>
                    <td style="WIDTH: 118px">
                        The page was generated at:</td>
                    <td>
                        <asp:Label id="lblOutputCacheMsg" runat="server"></asp:Label>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ outputcache duration="30" varybyparam="none" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="Server">
    Sub Page_Load()
        ' Create a Cache Dependency 
        ' using a CacheDependency object.
        Dim authorsDependency("authors.xml") As CacheDependency

        ' Make the page invalid if either of the
        ' cached items change or expire.        
        Response.AddCacheDependency(authorsDependency)

        ' Display the current time for cache reference
        lblOutputCacheMsg.Text = DateTime.Now.ToString()
        
        
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Cache Dependencies</title> 
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <table>
            <tbody>
                <tr>
                    <td style="WIDTH: 118px">
                        The page was generated at:</td>
                    <td>
                        <asp:Label id="lblOutputCacheMsg" runat="server"></asp:Label>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</body>
</html>

설명

AddCacheDependency 메서드를 사용하면 캐시된 응답과 CacheDependency 개체 간에 종속성을 만들 수 있습니다.

적용 대상

추가 정보