本文整理汇总了VB.NET中System.Runtime.Caching.HostFileChangeMonitor类的典型用法代码示例。如果您正苦于以下问题:VB.NET HostFileChangeMonitor类的具体用法?VB.NET HostFileChangeMonitor怎么用?VB.NET HostFileChangeMonitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HostFileChangeMonitor类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: TryCast
' 导入命名空间
Imports System.Runtime.Caching
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim cache As ObjectCache = MemoryCache.Default
Dim fileContents As String = TryCast(cache("filecontents"), _
String)
If fileContents Is Nothing Then
Dim policy As New CacheItemPolicy()
policy.AbsoluteExpiration = _
DateTimeOffset.Now.AddSeconds(10.0)
Dim filePaths As New List(Of String)()
Dim cachedFilePath As String = Server.MapPath("~") & _
"\cacheText.txt"
filePaths.Add(cachedFilePath)
policy.ChangeMonitors.Add(New _
HostFileChangeMonitor(filePaths))
' Fetch the file contents.
fileContents = File.ReadAllText(cachedFilePath) & _
vbCrLf & DateTime.Now.ToString()
cache.Set("filecontents", fileContents, policy)
End If
Label1.Text = fileContents
End Sub
End Class