开发者

Can I programmatically handle cached pages in webforms

For example, my home page shows a few of the newest products. I would like to set this page to be cached indefinitely, and then when I create a new product I could delete the cached page in my code, rather than caching for a certain time period, and hoping users are seeing the most up to date content.

Also, once I clear the cache can I use an HttpWebRequest to invoke those pa开发者_StackOverflow中文版ges to be cached again so that a user doesn't have to?

I understand that I can use partial page caching, but i'm really not interested in breaking up my pages into user controls.

Note: I do have access to the server, and IIS.


If the database your using is SQL Server, you can use SQL cache dependency (SqlCacheDependency) for the purpose of caching, it enable you to cache your pages that are dependent on data from database. As soon as the data in your database table changes, it will invalidate the cache and next time the new page will be generated... For more and sample, here is the link: http://msdn.microsoft.com/en-us/library/e3w8402y(v=vs.80).aspx and also from www.asp.net you can download a video tutorial too


If you don't have any action on the page (like submit,...) which causes Postback:

In Render sub of the page, get the page content string and set into the Application["YourKey"]. (On first call)

After that, in Page_Init you can simply check if the Application["YourKey"] has value, if yes, use response.write(Application["YourKey"]).

When you want to reset the cache, simply set the Application["YourKey"] to nothing.


When I reinstalled Windows and all the dev stuff on my desktop last week, I noted that IIS7 has a dynamic caching mode now. It's not installed by default. Here's some info on it. Hope it helps.

http://blogs.iis.net/bills/archive/2007/05/02/iis7-output-caching-for-dynamic-content-dramatically-speed-up-your-asp-and-php-applications.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜