Suppose I have two threads (Thread1, Thread2), where the threads access the cache for this object, for example, in the code below almost at the same time:
Dim expensiveToGetData = Cache("ExpensiveDataKey")
If ExpensiveToGetData is nothing then
'because the cache has expired
ExpensiveToGetData = LoadExpensiveDataFromDataSource()
Cache("ExpensiveDataKey") = ExpensiveToGetData
end If
ProcessExpensiveData(ExpensiveToGetData)
Is it not possible for both threads to load the cache because they both requested data from the cache that was nothing / expired? I conducted several tests on the local computer, and it seems that the cache loads more than once. Is this a normal template?
source
share