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

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

作者:互联网

原文链接:http://www.cnblogs.com/assion/archive/2009/05/10/1453613.html

 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一次执行比较好些!

转载于:https://www.cnblogs.com/assion/archive/2009/05/10/1453613.html

标签:缓存,数据库,Cache,List,cvs,访问,cvf,YddVisit,cv
来源: https://blog.csdn.net/weixin_30532369/article/details/95859667