cache reseting problem stumped

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an asp.net project with a business layer (project) that has a class
called references. It loads up a data set and stores in cache with the
following code.

_cached = CType(HttpContext.Current.Cache("cached"), String)
If HttpContext.Current.Cache("cached") Is Nothing Or _cached <>
"loaded" Then
MyBase.CreateCommand("SA_GetReferences", _connectionString)
_dsReferences = MyBase.ExecDataSet
HttpContext.Current.Cache.Insert("dsReferences", _dsReferences,
Nothing, DateTime.Now.AddMinutes(60), TimeSpan.Zero)
HttpContext.Current.Cache.Insert("cached", "loaded", Nothing,
DateTime.Now.AddMinutes(60), TimeSpan.Zero)
End If
_dsReferences = CType(HttpContext.Current.Cache("dsReferences"),
DataSet)



I have a number of properties that checks if in cache and if so returns the
appropriate datatable. If not then it loads up via above method..

Public ReadOnly Property dtLegalEntities() As DataTable
Get
LoadDs()
Return _dsReferences.Tables(9)
End Get
End Property


I also have a shared method to set cache to 'clear' in the few cases when i
want to clear it out.

Public Shared Sub ClearCache()
HttpContext.Current.Cache("cached") = "clear"
End Sub



The problem is that for some reason the app error's out complaining that
datatables are not in cache. I dont know how that is possible as with each
reference to the datatable it does the above check. I have made sure that
none of the cached tables are set to nothing.

any ideas on why this is happening? (i have used this technique in other
apps and have not seen this as a problem before).

thx
dave
 
I suggest you use the overloaded version of Cache.Insert, and specify
a CacheItemPriority of AboveNormal. Otherwise, it will be dumped from
the Cache asap. To see if this is what's happening, provide a
CacheItemRemovedCallback delegate parameter as well to Insert.
 
Back
Top