MVC: OutputCache and extremely slow RenderPartial

944 views Asked by At

I want to add caching to certain child actions, so I can separately cache parts of a single page.

I need the same controller method to be accessible both from AJAX and with RenderAction (or some other embedding method).

I've changed my code to use RenderAction and I've found that each Html.RenderAction adds around 1 second to the page loading time, when first load is so slow - it's hard to enjoy the fruits of the subsequent loads.

I've seen answers here on SO, advising to stay away from RenderAction...

So, what's the best strategy to sidestep the RenderAction lag and still be able to cache AND have a single method I can call from both HTML and AJAX? (and.. how to handle cache invalidation in this case?)

1

There are 1 answers

3
Softlion On BEST ANSWER

What is ajax doing here ? Are you returning a JSonResult if called from ajax and a ViewResult for normal calls ?

Try to use RenderAction with a razor view. The razor engine is faster. When the result is cached, renderaction is extremely fast (x1000).

For caching are you using the [OutputCache] attribute ? If so you can not invalidate the cache by yourself (or i don't know about it).

Or maybe you are using OutputCache with VaryByParam parameters which multiplies in-memory caches inneficiently.