Data stored in memory instances

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.