A code example that accesses frequently accessed table data into memory, and this code only loads data the first time you use ProductList.
It is then stored in memory and wants to update the cached data only if the Web site or IIS is restarted and the data is updated when the variable is used, so it is suitable for data stores with low data updates.
private static readonly Object _objproductlist = new Object ();
private static list<ent_tm_threemproduct> _productlist;
Public list<ent_tm_threemproduct> ProductList
{
Get
{
if (_productlist = = null)
{
Lock (_objproductlist)
{
Prevent multiple threads from accessing database tables multiple times while concurrently reading data
if (_productlist = = null)
{
using (productentitycontext context = new Productentitycontext ())
{
_productlist = context. Ent_tm_threemproduct.tolist ();
}
}
}
}
return _productlist;
}
}
Data stored in memory instances