views:

41

answers:

2

I have a heavy page that is cached. This is okay for anonymous users. They all see the same page.

The problem is for logged in users. They should have minor parts of the page re-rendered on every request (like personal notes on content in the page, etc.) But still all the rest of the page should be cached (it does tons of SQL and calcuations when rendered).

As a workaround I put placeholders in page templates (like #var1#, #var2#,..). Then I make controller method to render View into string, where I do string.Replace #var1# and other into real values.

Any cleaner way to do such kind of partial "non-caching"?

+2  A: 

This is called donut caching.

The ASP.Net MVC framework doesn't currently support it, but it's planned for version 3.

SLaks
+1  A: 

To start things off, it might make sense to go through the page and see if there is anything about it that you can do to streamline or reduce the weight. Depending upon how bad things are, investing some time here might pay off in the long run.

That said, in regards to trying to server the content to anonymous as well as logged in users, one option is to have two versions of the page: one for anonymous users and one for logged in users. This may not be the best approach though as it means that you now have two versions of the same page to maintain.

Given the lack of support doughnut caching mentioned by SLaks what I would likely do is try and cache the results of the calculations that are being done for the page (e.g. if you are querying a database for a table of data, cache a DataTable that you can check for before running the operation) and seeing what that does for the performance. It may not be the most elegant solution in the world, but it may solve the problems that you are having.

Rob