I am a web designer and usually design corporate web sites which often does not require update. So I want to cache the output for one day. How can I do this?
Also any suggestions for better performance for asp.net on slow servers are accepted.
I am a web designer and usually design corporate web sites which often does not require update. So I want to cache the output for one day. How can I do this?
Also any suggestions for better performance for asp.net on slow servers are accepted.
You use the outputcache directive
http://www.codeproject.com/KB/web-cache/cachingaspnet.aspx
10 Tips for Writing High-Performance Web Applications
I'd recommend you to follow this rules in order to improve performance in general
http://developer.yahoo.com/performance/rules.html
If you install the YSlow for firebug it will validate all these rules for you.
And regarding to cache in particular I recommend you to read this tutorial. Cache is a very extensive topic and it's not easy to explain everything in 10 lines :-)
http://www.mnot.net/cache_docs/#CONTROL
Specifically talking about the output cache directive for ASP NET pages, it's quite simple to use. Here you have the reference
http://msdn.microsoft.com/en-us/library/hdxfb6cy.aspx
But please take into account that is important to use the cache for pages and also for other resources as css, JS and images.
There is article I wrote years ago about asp.net caching. I believe you can understand the language :
http://www.csharpnedir.com/articles/read/?id=736&title=ASP.NET%27de
Be aware that ASP.NET caching has a bug since 1.0, that can effectively disable client-side caching.
That is why the HttpCachePolicy.SetOmitVaryStar()
method was added later as a workaround.
Developers should use it, but unfortunately, it seems that few of them know about the above method.
In response, the behavior is changed in ASP.NET 4.0, as detailed in the ASP.NET 4 Breaking Changes list:
In ASP.NET 1.0, a bug caused cached pages that specified Location="ServerAndClient" as an output–cache setting to emit a Vary:* HTTP header in the response. This had the effect of telling client browsers to never cache the page locally.
In ASP.NET 1.1, the System.Web.HttpCachePolicy.SetOmitVaryStar method was added, which you could call to suppress the Vary:* header. This method was chosen because changing the emitted HTTP header was considered a potentially breaking change at the time. However, developers have been confused by the behavior in ASP.NET, and bug reports suggest that developers are unaware of the existing SetOmitVaryStar behavior.
In ASP.NET 4, the decision was made to fix the root problem. The Vary:* HTTP header is no longer emitted from responses that specify the following directive:
<OutputCache Location="ServerAndClient" %>
As a result, SetOmitVaryStar is no longer needed in order to suppress the Vary:* header.
In applications that specify Location="ServerAndClient" in the @ OutputCache directive on a page, you will now see the behavior implied by the name of the Location attribute's value – that is, pages will be cacheable in the browser without requiring that you call the SetOmitVaryStar method.
If pages in your application must emit Vary:*, call the AppendHeader method, as in the following example:
HttpResponse.AppendHeader("Vary","*");
Alternatively, you can change the value of the output caching Location attribute to "Server".