views:

76

answers:

2

My application has an MVC structure.

Is it sufficient to only cache the model objects that are passed to the JSP views?

Or will there be a significant performance boost from caching the results of the rendering of the JSP views too?

A: 

Here's the mental algorithm that I would use:

  1. Are you experiencing performance issues (in other words: is your site slow)? If "no" goto step 6.
  2. Profile the code to find the bottlenecks (either a real profiler tool or just add timers that will measure time needed per request, etc.)
  3. Find the bottlenecks based on the data gathered in step 2.
  4. Try to find an algorithmic solution, i.e., compute the same result in a different way that requires less of the resources that constrain your bottleneck. If you find such an algorithm implement it and goto step 6.
  5. Decide on a strategy to mitigate this bottleneck. Caching is a solution to one kind of problems. In web-sites it is often the case that slowdown is due to downloading stuff. In that case you can make all your static content reside in a dedicated server (different domain) and have the web-pages specify content from the static site. Browser will open a 2nd connection to the static site which will dramatically improve performance.
  6. Refactor the code to make it maintainable, well structured, less error prone.
Itay
+1  A: 

I will not go into detail. Assuming that you know what you are doing.

Now to answer your question simply. We don't cache JSP views. As a normal practice, we cache database results for the queries which are gonna be used extensively. By the way, how are you planning to cache your JSP views?

Adeel Ansari
+1, I have a global filter that can see the result of the view, so I can cache the pages with that. I originally thought only caching the model would be sufficient, but I remember reading on the stackoverflow blog that they saw great improvements by caching portions of their views. They use ASP.NET MVC though, maybe rendering views on that is more expensive than rendering JSPs?
Kyle