AddCacheDependency or AddFileDependency?

What is the difference between Response.AddCacheDependency and Response.AddFileDependency in terms of implementing file dependency for cache? The following code seems to work in both cases, but which approach should I use?

Protected 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

      

+2


source to share


1 answer


The AddCacheDependency method uses a CacheDependency object that can represent dependencies on files or on objects other than files; whereas AddFileDpendency is only for use with files. The first one is more flexible, but you don't need it if you only have dependency files.



+2


source







All Articles