Search code examples
asp.netcachingcontent-expiration

Why is my asp.net caching throwing an exception?


I have a bunch of simple lookup tables cached in my asp.net application since the source data is on a seperate server from our main web architecture and it changes infrequently. I've been following answers here and various documentation and I have my initial load function call the following:

HttpContext.Current.Cache.Insert("CheckLocations", GetAllCheckLocations(), _
                                 Nothing, DateAdd(DateInterval.Day, 1, Now()), _
                                 System.Web.Caching.Cache.NoSlidingExpiration, _
                                 CacheItemPriority.Normal, _
                                 New CacheItemRemovedCallback(AddressOf CheckLocationsExpired))

For my cache expired callback, I have the following code.

Public Shared Sub CheckLocationsExpired(ByVal key As String, ByVal value As Object, ByVal reason As CacheItemRemovedReason)

   Dim dtCheckLocation As New ReferenceSchema.CheckLocationDataTable
   dtCheckLocation = GetAllCheckLocations()

   HttpContext.Current.Cache.Insert("CheckLocations", dtCheckLocation, Nothing, _
                                    DateAdd(DateInterval.Day, 1, Now()), _
                                    System.Web.Caching.Cache.NoSlidingExpiration, _
                                    CacheItemPriority.Normal, _
                                    New CacheItemRemovedCallback(AddressOf CheckLocationsExpired))

End Sub

For the record, the GetAllCheckLocations method simply calls a web service and parses the results into the data table being stored.

Now when I recompile the application for local testing, everything still functions fine, but I find the following exception message in my log file:

System.NullReferenceException: Object reference not set to an instance of an object. at EAF.CacheMethods.CheckLocationsExpired(String key, Object value, CacheItemRemovedReason reason) in C:\Projects\HR\EAF 2.0\DAL\CacheMethods.vb:line 434 at System.Web.Caching.CacheEntry.CallCacheItemRemovedCallback(CacheItemRemovedCallback callback, CacheItemRemovedReason reason)

I verify that the data is indeed there and up to date, and nothing in the command arguments seems out of place when I step through the debugger.

Does anybody know what I'm missing here? Is this another one of those "nuances" like the Reponse.Redirect issue where terminating the processing technically throws a thread abort exception?


Solution

  • Does it still exception out when you don't give it a callback function? Seems more like the delegated function is having issues with null objects.