Samuel
10/10/2006 6:32:00 PM
I have a weird problem using the cache in ASP.NET 2.0 on a WinXP Dual Core
Processor machine (AMD X2 3800+). I understand that each processor holds a
copy of the cache, but is it possible that one of the processor never holds a
copy?
This is my code:
================================
Public Class Forums
Public Const BaseForumCacheName As String = "The_BaseForums"
Public Shared Function GetBaseForums() As List(Of BaseForum)
Dim BaseForumCache As Object =
HttpContext.Current.Cache(BaseForumCacheName)
If BaseForumCache Is Nothing Then
Dim BaseForums As New List(Of BaseForum)
loadBaseForums(BaseForums)
Return BaseForums
Else
Return CType(BaseForumCache, List(Of BaseForum))
End If
End Function
Public Shared Sub loadBaseForums(ByVal BaseForums As List(Of
BaseForum))
Dim strSQL As String = "spGetBaseForums2"
Dim dt As New DataTable()
dt = GetDataTable(strSQL, CommandType.StoredProcedure)
Dim drs As DataRowCollection = dt.Rows
For Each dr As DataRow In drs
BaseForums.Add(New BaseForum(dr))
Next
Dim cacheTime As Double =
CDbl(ConfigurationManager.AppSettings("BaseForumCacheDurationInSeconds"))
If cacheTime > 0 Then
HttpContext.Current.Cache.Insert(BaseForumCacheName,
BaseForums, Nothing, DateTime.Now.AddSeconds(cacheTime),
Cache.NoSlidingExpiration)
End If
End Sub
End Class
===============================
BaseForum is a class I create that is the data structure, and GetDataTable
is just a helper method to return a DataTable from a query. Caching time is
currently 10 seconds. This Shared GetBaseForums() function is used as the
SelectMethod of an ObjectDataSource. The class is compiled as dll in the Bin
folder of the application.
The problem I have is that sometimes the cache mechnism doesn't seem to
work. I check using SQL profiler and found that each request generates a call
to the stored procedure "spGetBaseForums2" (called in the function
loadBaseForums above). However, sometimes it works as the SQL profiler does
not show a call to the say SP for around 10 seconds. I guess it is because I
am switch between the 2 processors, but I am not sure. How do I deal with
this issue?
Thanks for any pointers in advance!