开发者

Where to store data in order to avoid database hitting?

I am using webmethod which fetches data from database & storing it in a static variable so that next time it will not hit the database becoz the data is being accessed frequently. Creating static variable doesn't seem to be a proper solution what is an alernative to this scenario.

e.g

public static List<SupplierGridData> lstFullSupplierData;

public static List<SupplierGridData> GetProductData()
{
    if (lstFullSupplierData == null)
    {
        //first time get data from database
        lstFullSupplierData = new List<开发者_C百科;SupplierGridData>();
        lstFullSupplierData  = new POProcess().GetInquiryDetails();
    }
    else
    {
        //use lstFullSupplierData which holds data
    }
}


What you want is caching:

http://msdn.microsoft.com/en-us/library/xsbfdd8c.aspx

More specifically, caching data:

http://msdn.microsoft.com/en-us/library/6hbbsfk6.aspx

There is also Session State:

http://msdn.microsoft.com/en-us/library/ms972429.aspx

This comes in the per-application and per-user guise. And you can also change the backing store of session state.


The easiest solution to this could be hitting the db once if(!this.IsPostBack) then burying that stuff in the viewstate of the page if it's not too much stuff (assuming you don't need to carry across other pages). Otherwise session or cache will do as other people are suggesting.


You need to store your data in session in order to not hit the database again.

http://msdn.microsoft.com/en-us/library/ms178581.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜