Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey Guys,

I am looking to find the best way to cache the DB Lookup Tables which consists of about 75 table.

I want to cache these tables data to use them in my application so i won't open a connection with the DB each time i need them.

so Here is what i am doing:

1- i have created i static class contains static properties to each lookup table called (MyApplicatioCache).
2- each property in (get) i am filling it with the intended data from DB.
3- Put the result in HttpRuntime.Cache["PropertyName"]
4- each time i GET this lookup table data i make a check if the HttpRuntime.Cache["PropertyName"] Not equal Null.
5- if yes then i am getting it from cahce else i am getting it from DB
6- Finally, I am invoking all properties at application start event in global.asax

Untill now everything is good But Recently i've faced a performance issue and i can't solve it which is:

if i wanted the cache object (Payer) to be updated from DB i am doing this:

MyApplicationCache.Payer = null; //Sets HttpRuntime.Cache["Payer"] = null so if i requested it again it reloads From DB.

C#
list<payer> payerList = MyApplicationCache.Payer;


Now the Performance problem raises:
1- PayerList in DB are about 1700 record.
2- each payer object has a List property called PayerBranches which requires looping on all PayerList List and getting PayerBranches For Each PayerList Item.

//MyApplicationCache Payer Property:
C#
public static List<LDM.DataEntityTier.Payer> Payer
    {
        get
        {
            if (HttpRuntime.Cache["Payer"] != null) return (List<LDM.DataEntityTier.Payer>)HttpRuntime.Cache["Payer"];
            else
            {
                // request item from its original source
                using (LDM.DataAccess.OracleManager OracleManager = new LDM.DataAccess.OracleManager())
                {
                    OracleManager.OpenConnection();
                    List<LDM.DataEntityTier.Payer> result = new                                         LDM.DataService.PayerService().GetPayersListWithFullName(3, OracleManager, "UTC");
                    //List<LDM.DataEntityTier.Payer> result = new LDM.DataService.PayerService().GetListOfPayer("Order by Name asc", OracleManager ,"UTC");
                    List<PayerBranches> payerBranchesList = new LDM.DataService.PayerBranchesService().GetListOfObject(OracleManager, "UTC");
                    OracleManager.CloseConnection();
                    foreach (Payer payerItem in result)
                    {
                        payerItem.PayerBranches = new List<PayerBranches>();
                        foreach (PayerBranches item in payerBranchesList.FindAll(x => x.PayerID == payerItem.Id))
                        {
                            payerItem.PayerBranches.Add(item);
                        }
                    }
                    // add item to cache 
                    HttpRuntime.Cache["Payer"] = result;
                    return result;
                }
            }
        }
        set
        {
            if (value == null)
            {
                HttpRuntime.Cache.Remove("Payer");
            }
        }
    }


This Problem faced me with each property that have a list in it

i don't know if there is a better way to cache data or there is a problem in my code

That's the way i have worked.

Is there is any better way to do that???
Posted
Updated 18-Mar-14 23:29pm
v3
Comments
Kornfeld Eliyahu Peter 19-Mar-14 5:27am    
Did you heard about it - http://msdn.microsoft.com/en-us/library/ms178604.ASPX?
_ProgProg_ 19-Mar-14 5:38am    
No i didn't But i am using Oracle DB.
Do i have to search for OracleCacheDependency instead of SqlCacheDependency ?
Sampath Lokuge 19-Mar-14 5:56am    
Yes,You have to.
Sampath Lokuge 19-Mar-14 6:01am    
Check this : http://docs.oracle.com/html/E10928_01/OracleCacheDependencyClass.htm
another link : http://bumbasblog.blogspot.com/2011/06/oracle-cache-dependency-in-aspnet.html
_ProgProg_ 19-Mar-14 9:04am    
I read about oracle cache dependency but i think that it's almost like what i am doing?
So may be i din't get your point.
Would you please be more specific.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900