惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 刹那间我存在

一个可以放wordpress博客的PHP国外免费空间速度非常不错 重写alert,使用模态窗口强化alert。 - 刹那间我存在 - 博客园 JavaScript 使用for(…in…)实现反射机制 给moz添加ie方法和属性,让firefox像IE一样编程 - 刹那间我存在 - 博客园 [原] 用 javascript 给你的博客增加运行代码功能 [原]ASP.NET 下生成的条形码。 网页中图片大小自动调整三种方法 - 刹那间我存在 - 博客园 同时支持三种事件模型 ASP调用.Net编写的动态库 - 刹那间我存在 - 博客园 整个表单元素禁用``` shtml精简教程 更改数据库所有者 BitComet超级优化设置 很酷的TOOLTip JS函数收藏 今天得到了两个 Google Analytics 的邀请 CustomValidator 控件 千万数量级分页存储过程(带效果演示) 推荐一下免费的1G网络硬盘,非常另类
利用 ASP.NET 的Timer 来实现的访问统计,感觉比较适合高访问量的网站
刹那间我存在 · 2007-04-21 · via 博客园 - 刹那间我存在

首先是因为晚上我要把我的博客的访问统计加上去的.起初的想法很简单 随便在 Session_Start 里面,自动往数据表里加 1

但考虑到如果访问人数很高的话是不是每次都很频烦的访问(还好我的访问量并不高).

后来想到在Application_Start的时候存数据到 缓存里,Application_End 存进数据表不就得了,.貌似这个想法不错.但有一个问题,就是不可预测的因素,什么服务突然怎么怎么样啦.所以现在我的做法是,把数据 保存在 缓存里 然后利用timer间隔一定时间往数据表里写.

static Timer timer=new Timer(100 * 60*30);

    void Application_Start(object sender, EventArgs e)
    {
        /---省略---/

        string dtc = "1";
        if (dr.Read())
        {
            dtc = dr["vr_count"].ToString();
        }
        dr.Close();

        Application["total"] = dtc;
     
        timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
        timer.Interval = 100 * 60 * 30;
        timer.Enabled = true;
    }

void timer_Elapsed(object sender, ElapsedEventArgs e)
    {

        int total = Application["total"] != null ? Convert.ToInt32(Application["total"].ToString()) : 0;
        if (total != 0)
        {
            /--数据更新--/            
        }
    }

void Session_Start(object sender, EventArgs e)
    {
    

        if (Application["total"] == null)
        {
            int total=1;
            Application.Lock();
            Application["total"] = total;
            Application.UnLock();
        }
        else
        {
            int total = Application["total"] != null ? Convert.ToInt32(Application["total"].ToString()) : 0;
            Application.Lock();
            total++;
            Application["total"] = total;
            Application.UnLock();
        }

    }

很简单,,但效果已经达到了,,不知道这样做有没有什么不足,,望指教...
http://dubox.cn/content-44.aspx