如何:仅在更新时从数据库中检索值
我有一个场景,我想在网页上显示一堆数据。
仅在早上的特定时间(上午 7:00)或手动启动该进程,数据才会通过某个进程(我无法控制)填充到数据库中。 (PS 相同的数据也以不同的形式在网页上的其他地方使用,但来自不同的渠道。)
我正在考虑在页面上添加一些逻辑,
- 将数据检索到 xml 文件并从中读取数据xml 文件(以避免访问数据库)
- 仅在早上 7:10 时检索数据。但是,如果有人手动启动进程,数据库会更新,但我的网页要到早上 7:10 才会更新。即使 1 秒的数据不同步也是不可接受的。
做这个的最好方式是什么?有什么聪明的解决方案吗?我想避免一次又一次地往返数据库获取相同的数据。
SQL Server 2000、ASP。
I have a scenario where I want to display a bunch of data on a web page.
The data gets populated into database by some process (which I have no control over) only at (7:00 AM) a specific time in the morning or manually starting the process. (P.S The same data is also being used in some other place on the web page in a different form, but from a different channel.)
I was thinking to put in some logic on page that
- retrieve data into a xml file and read data from the xml file (to avoid trips to database)
- retrieve data only if it is 7:10 am in the morning. But if someone manually starts the process database is updated, but my web page won't be updated till 7:10 AM. Even 1 second out of sync of data is not acceptable.
What is the best way to do this? Any smart solutions? I want to avoid round trips to database for same data again and again.
SQL server 2000, ASP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可以使用 SqlCacheDependency 吗?
顺便说一句,不同步 1 秒并不是一个现实的目标。
Can you use a SqlCacheDependency?
And BTW, not being 1 second out of sync is not a realistic goal.
您将需要某种轮询解决方案。
就在我的头顶上,我会做这样的事情。
在正在填充的表(表 A)上设置一个触发器,以在插入和更新时更新另一个表上的某个控制标志,我们将其称为控制表。
将您的网站设置为在上午 7 点到上午 7:10 之间每 1 秒轮询一次控制表。如果控制表指示新数据已到达表 A,请获取它们并更新您的页面,否则,不执行任何操作。然而,虽然每秒轮询控制标志太大了,但您必须问自己,如果数据有几秒钟不同步,例如每 10 秒而不是每秒轮询一次,这真的是一个大问题吗? 。
You'll need some sort of polling solutions.
Just on top of my head, I'll do something like this.
Setup a trigger on the table (table A) that is being populated to update a certain control flag on another table upon inserts and udpates, lets call this the control table.
Setup your website to poll the control table say, every 1 second between 7am and 7:10am. If the control table indicates new data has arrived in table A, go grab them and update your page, otherwise, do nothing. However, although polling the control flag every second is too much of a big deal, you have to ask yourself is it really such a big issue if the data is a couple of seconds out of sync, say poll every 10 seconds instead of every second.
好吧,如果我没看错的话...
如果是相同的数据,您可以通过对适当的字段建立索引并将数据调整为结构上不太理想的形式以加快速度,从而减少访问数据库的负载查询。
问题是判断数据是否已更改的唯一方法是查询它,因此您无法真正避免轮询数据库。最安全的选择是优化结构和查询,以尽可能减少服务器上的负担。
Ok if I'm reading this right...
If it is the same data, you can reduce the load on trips to the database by indexing the appropriate fields and massaging the data into perhaps a not so structurally ideal form in order to speed up the queries.
The problem is that the only way to tell whether the data has been changed or not is to query it, so you can't really avoid polling the DB. The safest bety would be to optimize the structure and the queries to make the taxing on the server as minimal as possible.