如何添加只评估一次的天气信息?
在 ASP.MVC (1.0) 项目中,我设法从 RSS 提要获取天气信息并将其显示出来。我遇到的问题是性能:
我在 Site.Master 文件中放置了 RenderAction() 方法(效果很好),但我担心如果用户在菜单上几秒钟后单击菜单点 1,它将如何表现第 2 点,在菜单点 3 上几秒钟后,...从而使 RSS 提要一次又一次地请求新信息!
这可以通过某种方式避免吗? (以某种方式仅加载此信息一次?)
提前致谢!
In a ASP.MVC (1.0) project i managed to get weather info from a RSS feed and to show it up. The problem i have is performance:
i have put a RenderAction() Method in the Site.Master file (which works perfectly) but i 'm worried about how it will behave if a user clicks on menu point 1, after some seconds on menu point 2, after some seconds on menu point 3, .... thus making the RSS feed requesting new info again and again and again!
Can this somehow be avoided? (to somehow load this info only once?)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用服务器缓存:
You could use the server cache:
我想如果我编写这个应用程序,我会下载天气详细信息并将它们存储在本地的 db 或 xml 文件中并从中读取。
天气变化不会太大,除非你是天气频道或其他什么,否则你需要每分钟更新。
或者,您可以将其编写为线程,并让它在加载完成时报告。顺便说一句,VS 2010 使这变得轻而易举。
因此,要解决这个问题,可能需要让您的代码能够取消请求,并且为此您不能将其作为单线程应用程序运行。您将需要能够在线程上启动请求并在另一个请求上取消该请求。
面对这种情况,我会在本地托管它,并每隔一小时运行一个进程来更新 RSS 提要中的数据。
I think if I were writting this app I'd download the weather details and store them in a db or xml file locally and read from that.
Weather doesn't change that much that you need minute by minute updates unless you're the weather channel or something.
Alternatively you could write this as a thread and have it report back when it's done loading. VS 2010 makes this a piece of cake btw.
So to solve this might be to give your code the ability to cancel a request and to do that you can't run this as a single threaded application. You are going to need to have the ability to kick off a request on a thread and cancel that on another request.
Faced with that I'd host it locally and run a process every say hour to update the data from the RSS feed.