利用缓存技术解决访问统计数据库压力

 cacheVisit cv=new cacheVisit();
                    cv.sysno=sysno;
                    cv.reurl=reurl;
                    cv.ip=GetIpV4AndV6();
                    cv.moduleclass=moduleclass;

 

                    if (Cache["YddVisit"] == null)
                    {
                        List<cacheVisit> cvs = new List<cacheVisit>();
                        cvs.Add(cv);
                        Cache.Insert("YddVisit", cvs);
                    }
                    else
                    {
                        List<cacheVisit> cvs = (List<cacheVisit>)Cache["YddVisit"];
                        if (cvs.Count < 10)
                        {

                            cvs.Add(cv);
                            Cache.Insert("YddVisit", cvs);
                        }
                        else
                        {
                            List<cacheVisit> cvs2 = (List<cacheVisit>)Cache["YddVisit"];

                            foreach (cacheVisit cvf in cvs2)
                            {
                                if (cvf.reurl == "")
                                    EC.Biz.ICBC.ICBC_Product_DailyClickManager.GetInstance().Add(cvf.sysno, "", cvf.ip, cvf.moduleclass);
                                else
                                    EC.Biz.ICBC.ICBC_Product_DailyClickManager.GetInstance().Add(cvf.sysno, cvf.reurl, cvf.ip, cvf.moduleclass);
                            }

                            Cache.Remove("YddVisit");
                        }
                    }

 

 

每当有10条时统一更新到数据库,实际应该是拼SQL一次执行比较好些!

posted @ 2009-05-10 13:29  Assion Yang  阅读(768)  评论(1编辑  收藏  举报