Reputation: 16441
We know we can store and retrieve data in HTTP Session. Is there any out of the box way to store the data in the Session, that will be automatically destroyed after a certain period of time (while the Session still stays and keeps other data stored)?
Upvotes: 0
Views: 656
Reputation: 22553
You won't get this for free. If I were needed this feature and had a spring based application, then I might create a session based bean that wrapped some simple cache. Being lazy, I might use the guava cache:
https://code.google.com/p/guava-libraries/wiki/CachesExplained
If I wasn't using spring, I would do the same, perhaps putting the cache on the ServletContext and making sure that the cache key was partially comprised by some identifier for the current user (like the session id).
You could even put the guava, or other cache directly on the user session (you might do that when the session is created). Your access method is always going to feel a little different than accessing your naked session.
Depending on your servlet container, you could go so far as replace the session implementation with your own.
Upvotes: 1