在一个页面上显示#视图,而不必一直打开数据库 [英] displaying # views on a page without hitting database all the time

查看:102
本文介绍了在一个页面上显示#视图,而不必一直打开数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

越来越多的网站显示某些网页收到的观看次数(和点击次数在dzone.com上)。什么是跟踪视图#的最佳实践,而不会在每次加载数据库时触及数据库?

More and more sites are displaying the number of views (and clicks like on dzone.com) certain pages receive. What is the best practice for keeping track of view #'s without hitting the database every load?

我有一堆关于如何在我的头上这么做的潜在想法

I have a bunch of potential ideas on how to do this in my head but none of them seem viable.

感谢,
第一次使用者。

Thanks, first time user.

推荐答案

我会首先尝试数据库方法 - 返回一个autoincrement计数器的值应该是一个相当便宜的操作,所以你可能会感到惊讶。即使保存许多项目的表,其中记录命中计数应该是相当高效的。

I would try the database approach first - returning the value of an autoincrement counter should be a fairly cheap operation so you might be surprised. Even keeping a table of many items on which to record the hit count should be fairly performant.

但问题是如何避免击中数据库每个调用。我建议将表加载到webapp,并增加它在那里,只定期备份到db或webapp关闭。

But the question was how to avoid hitting the db every call. I'd suggest loading the table into the webapp and incrementing it there, only backing it up to the db periodically or on webapp shutdown.

这篇关于在一个页面上显示#视图,而不必一直打开数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆