现在我正在处理ASP.NET项目,并希望使用Page.Cache属性来缓存字符串数据,如下面所示。但是,它的行为就像有一个会话范围。据我所知,Page.Cache属性正在重新调整当前的System.Caching.Cache对象,该对象必须具有应用程序范围。我可以检查下面的代码工作正常,但我的项目的代码不是-它使每个会话的缓存。
而且,它取代了Cache of Application (使用Lock和UnLock)也很好。
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim key_str As String = "cache_key"
Dim cached_value = Cache.Get(key_str)
If cached_value Is Nothing Then
cached_value = "stored_value"
Cache.Insert(key_str, cached_value, Nothing, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(5), CacheItemPriority.Normal, New CacheItemRemovedCallback(AddressOf RemovedCallback))
End If
Label1.Text = cached_value
End Sub
Public Sub RemovedCallback(ByVal key As String, ByVal value As Object, ByVal removedReason As CacheItemRemovedReason)
Debug.WriteLine("#Callback!")
End Sub
End Class
Cache替换为Application,那就很好了
有没有可能发生这样的行为?(还是我在逻辑学中的其他地方犯了一个错误?)
请指出是否涉及一些配置文件。
发布于 2013-12-03 10:29:42
我可能犯了个错误。我的项目是Azure项目,所以Page.Cache要为每个azure实例存储数据?对吗?
https://stackoverflow.com/questions/20310729
复制相似问题