简体   繁体   中英

Caching dynamic pages in ASP.NET 4.0

This is our setup:

Windows 2003 Server Standard, SQL 2005 and 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.

Is it possible to do caching based on this URL and if so, how would this be accomplished? I have looked at VaryByParam option of the ASP.NET caching, eg

<%@ 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? 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.

In the case you describe, what you want is VaryByCustom. To make that work, override the GetVaryByCustomString() method in Global.asax. ASP.NET will store a different version of the page for each unique string you return from that method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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