I have a slow and expensive method that return some data for me:
public Data GetData(){...}
I don't want to wait until this method will execute. Rather than I want to return a cached data immediately.
I have a class CachedData
that contains one property Data cachedData
.
So I want to create another method public CachedData GetCachedData()
that will initiate a new task(call GetData
inside of it) and immediately return cached data and after task will finish we will update the cache.
I need to have thread safe GetCachedData()
because I will have multiple request that will call this method.
I will have a light ping "is there anything change?" each minute and if it will return true (cachedData != currentData) then I will call GetCachedData()
.
I'm new in C#
. Please, help me to implement this method.
I'm using .net framework 4.5.2