gbtimmon
gbtimmon

Reputation: 4322

Caching a jsp for the server side

I have a 'search' page that let the user select some search by options. These option include a number of dropdowns filled by the database. These dropdowns might change but will rarely (once a month at most).

Right now our page hits the database everytime it loads the page to fill these dropdowns, and page load is roughly 3-4 seconds. I want it to cache the page server side and only have the jsp be processed every hour or so. Any request that comes in should get the most recent output of the processed jsp, but not cause the server to reprocess it. That is, I want page refresh to always be sepreate from the get method so now user will never have to wait more the .5 sec to get the page.

Is it possible to server side cache a jsp page like you can in asp ( Is it possible to cache an asp page on the server side? ) to solve this problem? What approaches are generally used to solve this problem? I can think of solutions, but I dont want to reinvent the wheel if common best practices have already been developed, which I know they must have been.

thanks!

Upvotes: 1

Views: 1070

Answers (3)

gavenkoa
gavenkoa

Reputation: 48753

What about JSTL c:set? Here example of menu caching:

<c:if test="${empty JSPCACHE_menu}">
  <c:set var="JSPCACHE_menu" scope="session">
    <ul id="user-menu">...</ul>
  </c:set>
</c:if>
${JSPCACHE_menu}

Upvotes: 1

Jigar Parekh
Jigar Parekh

Reputation: 6273

if you are using spring then i think spring cache abstraction is for also rescue. i have used this in same kind of scenario where i am caching output of controller methods and some service methods. Spring cache provide good use of cache as cross cutting concern.

Upvotes: 0

tom
tom

Reputation: 2745

I don't know about jsp caching server side but you can also cache the result of the database since this is most likely the slowest part.

I always use ehcache together with spring and aop to implement non-intrusive caching of the result of java methods.

Upvotes: 2

Related Questions