Note to self– Use OutputCache in MVC 3

I’m just reading ScottGu’s post on the MVC 3 release candidate.

What got me really thinking was the output cache attribute:


Scott explains:

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.

So, with my Windows Azure Feedreader in mind,  my note to self is as follows:

In a couple of weeks, when we get to the shared items Rss feed, we can use this code. We vary by user id rather than by category in the example above.

I’m actually quite relived, as I was wondering how we’d do the shared items Rss feed. These actions would, arguably, be highly trafficked and reading directly from the blobs (which was my original plan) would be too bandwidth intensive. Problem solved.

I’m very excited about MVC 3 as a whole, but when i see the direct application of features, I get even more excited.

In fact, when Razor first came out, I really was going to use it for the Feedreader instead.