We don't hold the lock around the cache while initializing stored values so that the cache can be called re-entrantly. In the single-threaded case this has obvious behavior. In the multi-threaded case it's quite likely for multiple clients of a query to simultaneously find the cache needs to be populated and to run the query multiple times between them.
To prevent that we need some kind of value synchronization for readers that is tied only to the specific cache value, not to the overall cache.
We don't hold the lock around the cache while initializing stored values so that the cache can be called re-entrantly. In the single-threaded case this has obvious behavior. In the multi-threaded case it's quite likely for multiple clients of a query to simultaneously find the cache needs to be populated and to run the query multiple times between them.
To prevent that we need some kind of value synchronization for readers that is tied only to the specific cache value, not to the overall cache.