This tutorial shows how to use basic caching to improve the performance of a website. C# version.

We can add the following line of code to the top of our ASPX pages to set a duration that the page is valid for. With the below example, the page will not be reloaded during the 15 second timeframe. This means that if the user was to refresh the page within those 15 seconds, the cache version would be loaded.

Example: If we had a label that displayed the time (as below), the time would only be updated if the page was reloaded after the 15 second timeframe.

The above example of caching is page-specific. If we wanted to cache pages on a larger scale on our website, we could use Application-Level Caching.
This is done by modifying the Web.config file:

And then modifying the ASPX directive:

This directive refers to the Cache Profile specified in the Web.config file.
However, there are yet more ways we can use caching. We can cache pages using parameters (VaryByParam). This will enable ASP.NET to store different variations of the page depending on certain parameters such as query strings, post values, request headers, etc.
We can create an example of this by changing the color of the label that holds the current time. We create a textbox and a button, and allow the user to type a color to change the label. Every time the color changes, the time should change. However, if the color remains the same, and the page is still within its duration specified in the directive (60 seconds), then the time will stay the same. This is because it is the cached version of the page which is being loaded.
So we change the directive once again to add the parameters:

And our ASPX page will look something like this:

The code-behind will be something like this:

Download Source Files