Is cacheitemremovedcallback HttpRuntime.Cache thread safe?

I am using HttpRuntime.Cache.Insert to insert data into the cache. I have a function "onremove" as cacheitemremovedcallback - when the cache expires (after 15 minutes) it frees data in the cache and calls "onremove", which again inserts the data into the cache.

every time 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]

Is HttpRuntime.Cache expected until it cancels "onremove" and finishes loading the data back into the cache before it retrieves the data?

+3

Source: https://habr.com/ru/post/1774038/


All Articles