This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I need to display the search results using struts and display tag. Following are the ways i have in mind to implement this but i would like to know the best optimal solution before start my development.
1) retreive the complete search results and store into the HttpSession object. This may be a performance bottleneck if concurrent sessions opened.
2) retrieve the records from database on demand (let say 10 records per user hit). Results in more number of costly database calls.
3) retreive the part from database and store into the HttpSession object, let say my search results in 1000 matching records and i will get the first 100 records from the database and put it in the HttpSession object. When the user clicks on page 11, i will query the database again and retreive another 100 recods and store/overwrite into HttpSession object. I think this is the better approach among the above three.
Please let me know if you have any other better solution and how to implement.
There is usually not a single "best" solution that fits all applications. Your #3 sounds good, but it is also the solution that requires the most work to implement, debug, document and maintain. If you are dealing with small sets of data you may want to not do any caching yourself and let the database handle that.