I am facing a problem in using HTTPRuntime Caching in ASP.net web api. i am adding a datatable in cache using below code.
function getDatatable(key) as datatable
if HttpRuntime.Cache(Key) is nothing = True THEN
// Get Datatable
HttpRuntime.Cache.Remove(Key)
HttpRuntime.Cache.Add(Key, Obj, Nothing, System.DateTime.Now.AddMinutes(TimeInMinutes), System.Web.Caching.Cache.NoSlidingExpiration, Caching.CacheItemPriority.Normal, OnRemoveCallback)
return datatable
else
return HttpRuntime.Cache(Key) // this return as datatable
End if
End function
now i am using this data table in another function
Dim dtResult = getDatatable(key)
if dtResult is nothing = false andAlso dtResult.rows.count > 0 then
// Get Datatable columns
End if
This is working perfectly fine with less number of users, but if there are concurrent request to this function then while getting column values it throw exception while getting value from datatable like converting dbnull to decimal. This happening for few requests and then works fine.
is there any way to track that what actually happens that in one request if application is getting value from datatable and at same time another request remove caching even then that datatable scope is limited in other function and must not effect.