I'm trying to understand the ASP.NET OutputCache mechanism.
I built a test page with a Label and LinkButton.
The label text is being initialized on the server with the current server date on every PageLoad:
protected void Page_Load(object sender, EventArgs e)
{
lblDate.Text = DateTime.Now.ToString();
}
I used this directive: <%@ OutputCache Duration="600" VaryByParam="none"%>
When I press the LinkButton the first time I get a new text in the Label but if I press the linkbutton again I don't get a new text.
I assume this is because of the parameters that are being transfered to the server that are the same for each postback.
Is there any way to work with OutputCach and postback controls?
Right, the thing is you're varying by NO parameter so the first request's response html is cached and served for the next 10 minutes (in theory). If you want to cache GETs but process different POSTs you should vary by your POST params.
Let me give you an example. You have a text input used to send an email with its content on POST. If you vary by that input name, each request within the caching time span with different values for that text input would hit your handler and process sending the email.
On the other side you could vary by * but then you'd lose kernel mode caching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With