HttpRuntime.Cache在客户端/服务器端执行缓存
问题描述:
我在asp.net Web应用程序的global.asax文件中声明的HttpRuntime.Cache是否在客户端或服务器端进行缓存?HttpRuntime.Cache在客户端/服务器端执行缓存
HttpRuntime.Cache["Key"]
也有任何机会,我们可以设置这段代码的滑动到期?
在此先感谢。
编辑: 我认为这将是很多思考后的可能的解决方案。
为整个asp.net web应用程序放置一个basePage类,其中所有system.web.ui.page都将从此类继承。
和下面的代码
protected override void OnInit(EventArgs e)
{
OutputCacheParameters aa = new OutputCacheParameters();
aa.Location = OutputCacheLocation.Client;<-- I am not sure whether this will work and gets added to the pages correctly or not.Any Ideas on these two lines of code.
base.OnInit(e);
Cache.Add("State", "", null, DateTime.Now.AddMinutes(20), Cache.NoSlidingExpiration, CacheItemPriority.High, null);
Cache.Add("StatesGlobal", "", null, Cache.NoAbsoluteExpiration, new TimeSpan(1,0,0,0,0), CacheItemPriority.High, null);
}
答
在服务器上。
如果你想设置的过期策略的项目,你应该使用Cache.Add API:
http://msdn.microsoft.com/en-us/library/system.web.caching.cache.add.aspx
你给我一半一片面包,我期待的。但是如何根据客户端服务器为此设置位置。或者是否有任何默认位置。根据你的网址“onRemoveCallback”,我们可以有任何其他的解决方法,而不是定义回调方法,如把null或类似的东西? Thnks为快速回复。 – hungrycoder 2012-08-12 21:33:22