本文整理汇总了VB.NET中System.Runtime.Caching.CacheItem类的典型用法代码示例。如果您正苦于以下问题:VB.NET CacheItem类的具体用法?VB.NET CacheItem怎么用?VB.NET CacheItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CacheItem类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: CacheItemPolicy
' 导入命名空间
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 CacheItem = cache.GetCacheItem("filecontents")
If fileContents Is Nothing Then
Dim policy As New CacheItemPolicy()
Dim filePaths As New List(Of String)()
Dim CachedFilePaths As String = Server.MapPath("~") & "\cacheText.txt"
filePaths.Add(CachedFilePaths)
policy.ChangeMonitors.Add(New HostFileChangeMonitor(filePaths))
' Fetch the file contents
Dim fileData As String = File.ReadAllText(CachedFilePaths)
fileContents = New CacheItem("filecontents", fileData)
cache.Set(fileContents, policy)
End If
Label1.Text = TryCast(fileContents.Value, String)
End Sub
End Class