3

i use HttpRuntime.Cache.Insert to insert data into cache. i have the function 'onremove' as the cacheitemremovedcallback - when the cache expires (after 15 minutes) it releases data in cache and calls 'onremove' that insert the data again to the cache.

everytime i want to use the data in the cache i check that the data is there first:

if (HttpRuntime.Cache[CACHE_DATA_TABLE] == null)
            { // load data into cache again}

what happens if i check that the data is in the cache and it is there, but as soon as i want to use it it expires? so when i call:

DATADT = (DataTable)HttpRuntime.Cache[CACHE_DATA_TABLE]

Does the HttpRuntime.Cache waits untill 'onremove' is called and finish loading the data back into cache before it extract the data ?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Rodniko
  • 4,926
  • 20
  • 69
  • 93

1 Answers1

1

You should use a CacheItemUpdateCallback delegate instead.

This lets you take the desired action before the item is about to be removed.

See: MSDN on Cache.Insert Method (String, Object, CacheDependency, DateTime, TimeSpan, CacheItemUpdateCallback)