开发者

AddCacheDependency or AddFileDependency?

开发者 https://www.devze.com 2022-12-09 07:00 出处:网络
What’s the difference between Response.AddCacheDependency and Response.AddFileDependency in terms of implementing a file dependency for a cache? The following code seems to work in both cases but whi

What’s the difference between Response.AddCacheDependency and Response.AddFileDependency in terms of implementing a file dependency for a cache? The following code seems to work in both cases but which approach should I be using?

Protec开发者_StackOverflow社区ted Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim authorsDependency As New CacheDependency(Server.MapPath("authors.xml"))
        Response.AddCacheDependency(authorsDependency)
        Response.Cache.SetCacheability(HttpCacheability.Public)
        Response.Cache.SetValidUntilExpires(True)

        Response.Write(DateTime.Now.ToString())

    End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Response.AddFileDependency(Server.MapPath("authors.xml"))
        Response.Cache.SetCacheability(HttpCacheability.Public)
        Response.Cache.SetValidUntilExpires(True)

        Response.Write(DateTime.Now.ToString())

    End Sub


The AddCacheDependency method uses a CacheDependency object which can represent dependencies with files, or with objects other than files; whereas AddFileDpendency is meant just for use with files. The former is more flexible but you don't need it if you only have file dependencies.

0

精彩评论

暂无评论...
验证码 换一张
取 消