Sponsor: Interested in learning more about Distributed Systems Design? Enter for a chance to win a 5 day Advanced Distributed Systems Design course led by Udi Dahan founder of Particular Software, and creator of NServiceBus.
I’ve been moving some data access code to to use Lazy<T> whenever I want to defer actually fetching the data until it’s first needed. What I’ve always found interesting is there is no Lazy Async.
In the exact use case it’s when an application loads, there is some static data loaded from a database. This data is the cached for later use.
However, in many situations it’s not actually needed until much later if at all. Why take the performance hit of fetching the data on app startup if that data is often times not needed?
That’s the whole purpose of Lazy<T>. But as mentioned, why is there no Lazy Async? If i want to defer IO, that’s generally async.
Here is more info on Lazy Initialization if it’s new to you.