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.
精彩评论