I have singleton that fetches from DB, hence it is expensive load. It is lazy loaded.
I would like to create a method that refreshes that singleton and populates it once it is required.
the data is DB and very expensive, so I want to refresh it only once in case I have concurrent calls. (that is, if I get 500 calls to refresh, I want to restart the refresh only once)
public static PageData Instance
{
get
{
if (m_Instance == null)
{
lock (instanceLock)
{
if (m_Instance == null)
{
m_Instance = new PageData();
}
}
}
return m_Instance;
}
}
public void ReSync()
{
lock (instanceLock)
{
/* Setting to null to force the Instance to re-build */
m_Instance = null;
PageData pData = Instance;
}
}
thanks