ASP.Net缓存 [英] ASP.Net Caching

查看:96
本文介绍了ASP.Net缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,从凌晨3点第三方每天早晨下载数据
没有在内容方面的变化,直到然后...

I've got an application that downloads data from a 3rd party at 3am every morning Nothing changes in terms of content until then...

有可能缓存产品信息页面,直到呢?
或者这是我应该在Global.asax中设置?

is it possible to cache the "product info" page until then? or is this something i should set in global.asax?

推荐答案

是的,你可以缓存,直到然后。有这样做的许多方面。

Yes you can cache it until then. There are many ways of doing this.

如果你有一个服务器端的调用来检索数据,那么我就这个简单的数据添加到缓存中,当你第一次得到它,设置到期是凌晨3点的第二天。然后在每个页面调用检查缓存此数据对象,如果返回null,启动数据的另一种获取。

If you have a serverside call to retrieve the data then I would simply add this data to the cache when you first get it and set the expiration to be 3am the following day. Then on each page call check the cache for this data object and if it returns null, initiate another fetch of the data.

您可以使用页面输出cacheing太但这不给你这样详细的控制。

You can use page output cacheing too but this does not give you such detailed control.

是这样的:

if (HttpContext.Current.Cache["MyData"] != null)
  return HttpContext.Current.Cache["MyData"] as DataObjectClass

//Get data into dataobject

HttpContext.Current.Cache.Add(
                  "MyData",
                  DataObject,
                  DateTime (tomorrow 3am),  // psuedo
                  null,
                  TimeSpan.Zero,
                  System.Web.Caching.CacheItemPriority.Normal,
                  null);

return DataObject;

这篇关于ASP.Net缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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