File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Expiring session data

 
Michael J. Makunas
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to make objects that are stored in the session "expire" after a set amount of time even though the session is still valid? I know I could add some sort of time stamp to the data structure and check that timistamp the next time I retrieve the object from the session. What I really want is for these objects to remove themselves after a certain amount of time.
 
Scott Dunbar
Ranch Hand
Posts: 245
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't a standard that addresses this. If you want individual objects to timeout at a different time than the session you'll have to do some sort of custom coding to remove them.

Perhaps you can use the session getLastAccessedTime() and flush out "semi-old" objects as needed. That is, maybe your overall session timeout is 30 minutes. But on a request you could look at the session and check to see if it has been accessed within the last 15 minutes. If so, you would toast the objects that you want. This could be done in a Filter which would then be transparent to your servlets. Just a thought.
 
Michael J. Makunas
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm....I've heard about filters but I've never used them before. I just did a quick search on them and they look really useful for some other things I'm doing. Thanks for the idea!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's almost exactly what we do: use a filter to check a timestamp in a session token.
 
Naveen Garg
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use session.setMaxInactiveInterval(time in miliseconds) methods to set the time a session should exists.

Originally posted by Michael J. Makunas:
Is there a way to make objects that are stored in the session "expire" after a set amount of time even though the session is still valid? I know I could add some sort of time stamp to the data structure and check that timistamp the next time I retrieve the object from the session. What I really want is for these objects to remove themselves after a certain amount of time.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic