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

原文链接: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

上一篇:linux常用命令---tar压缩、解压对应关系


下一篇:Linux命令学习-tar命令