简体   繁体   English

在ASP.NET 4.0中缓存动态页面

[英]Caching dynamic pages in ASP.NET 4.0

This is our setup: 这是我们的设置:

Windows 2003 Server Standard, SQL 2005 and ASP.NET 4.0. Windows 2003 Server标准版,SQL 2005和ASP.NET 4.0。

We have a news site where URLs are structured like www.domain.com/This-is-my-headline-123.aspx - where 123 is the ID pointing at a record in the SQL database. 我们有一个新闻站点,其URL的结构类似于www.domain.com/This-is-my-headline-123.aspx其中123是指向SQL数据库中记录的ID。

Is it possible to do caching based on this URL and if so, how would this be accomplished? 是否可以基于此URL进行缓存,如果可以,该如何实现? I have looked at VaryByParam option of the ASP.NET caching, eg 我看了ASP.NET缓存的VaryByParam选项,例如

<%@ OutputCache Duration="3600" VaryByParam="*"%>

But I am unsure what the best practice would be. 但是我不确定最佳做法是什么。 I have read this: 我读了这个:

Is DiskCacheProvider in ASP.Net 4.0 really exist? ASP.Net 4.0中的DiskCacheProvider确实存在吗? with disk caching and I think this is the way to go - but do you guys/gals have some input for optimal techniques to improve performance? 使用磁盘缓存,我认为这是可行的方法-但是你们是否对优化性能的最佳技术有一些投入?

You use VaryByParam to vary the output cache based on query string or POST parameters. 您可以使用VaryByParam根据查询字符串或POST参数来更改输出缓存。

In the case you describe, what you want is VaryByCustom. 在您描述的情况下,您想要的是VaryByCustom。 To make that work, override the GetVaryByCustomString() method in Global.asax. 为此,请覆盖Global.asax中的GetVaryByCustomString()方法。 ASP.NET will store a different version of the page for each unique string you return from that method. ASP.NET将为从该方法返回的每个唯一字符串存储页面的不同版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM