user1922329
user1922329

Reputation: 31

Storing user data in Cache/session in Spring based web application

In my project we provide search functionality to user.user can set values in 2 dozen search parameters available.On search we fetch the search result plus store the searchparameters (which were selected by user ) in database(this is causing a serious performance prob),so that next time when the user come to search page his previous search parameter are loaded on page load.

I want to store the search parameter in session or cache (during the entire user session) and when user logs out commit them to database ,instead of committing to database on every search.When user comes to search page DAO checks for value of search parameter first in cache/session then try to fetch from DB. Can anyone suggest any solution for this problem Technology used- Spring 3+ Hibernate 3.6 + Tomcat 6 + EHCache +JSP

Upvotes: 0

Views: 1313

Answers (1)

nickdos
nickdos

Reputation: 8414

Take a look at the Spring EhCache project. It basically caches the return value of a method given a certain (set of) method signature values. There are quite a few caveats, such as the class must implement an interface and method args should be either a primitive, String or a class that is serializable (implements hash code at least).

Getting the ehcache.xml conf file right can be tricky at first as you really do need to read the docs. But once setup, it is pretty straight forward to implement and it is fast.

So you would need to write methods: to populate the search parameters from the UI, a method to return them (cached), another method to store it in the database and then invalidate/clear the cache.

Upvotes: 1

Related Questions