ASP.NET MVC has supported output caching of full page
responses since V1. With ASP.NET MVC V3 (starting with today’s RC) we are
also enabling support for partial page output caching – which allows you to
easily output cache regions or fragments of a response as opposed to the entire
thing. This ends up being super useful in a lot of scenarios.
Output caching just a region of a page is really easy
to-do. Simply encapsulate the region you want to output cache within a
child action that you invoke from within the view that you are rendering.
For example, below I have a product listing page, and I want to output a “Daily
Specials” section on the page as well:

Above I’m using the Html.Action() helper method to call the
SalesController.DailySpecials() child action method. Notice that I’m
passing a category parameter to it above – which will allow me to customize the
“Daily Specials” I display based on what types of products the user is
currently browsing (that way if they are browsing “computer” products I can
display a list of computer specials, and if they are browsing “baby” products I
can display diaper specials).
Below is a simple implementation of the
SalesController.DailySpecials() method. It retrieves an appropriate list
of products and then renders back a response using a Razor partial view
template:

Notice how the DailySpecials method above has an
[OutputCache] attribute on it. This indicates that the partial content
rendered by it should be cached (for 3600 seconds/1 hour). We are also
indicating that the cached content should automatically vary based on the
category parameter.
If we have 10 categories of products, our DailySpecials
method will end up caching 10 different lists of specials – and the appropriate
specials list (computers or diapers) will be output depending upon what product
category the user is browsing in. Importantly: no database access or
processing logic will happen if the partial content is served out of the output
cache – which will reduce the load on our server and speed up the response
time.
This new mechanism provides a pretty clean and easy way to
add partial-page output caching to your applications.