Maintaining the state information in the URL or in hidden form fields avoids some nasty and difficult to correct problems you may encounter down the road.
When you maintain the criteria in a session or cookie there is only one copy of this criteria per user. If a user opens two windows and starts two different queries, then one of the criteria sets will be lost and both windows will end up with the same settings.
This can be confusing and frustrating to the user. Storing the state information in something related to that window's history (URL or hidden form fields) keeps their histories distinct as the user would have a right to expect.
Avoiding the session strategy also has the benefit of not needing to increase the storage requirements on the server side.
This is not to say that sessions are inherenty bad for all purposes. Some of my best applications use sessions.
That said, let's assume you are using sessions for some reason (good or bad) and you need to prevent their storage from taking over your hard drive. The standard way to do this is to expire the session after some elapsed period of non-use.
For example, if a user of a session does not request a page in 30 minutes, that session can be deleted.
There are a couple issues that spring to mind:
1. You will need to store the time the session was last accessed. This needs to be updated every time the session is accessed, even if the other data in the session does not change. This may have performance issues if you have really high volume. In fact, I had to replace Apache::Session (Oracle) with my own hand-optimized session code because of really high traffic. You probably should not worry about this.
2. You will need to create a process which regularly deletes sessions that have not been accessed in the last N minutes. This is fairly simple to do if you are storing one session per file as you can check the timestamp on the file, but requires you to iterate over every single session if you are using one of the Apache::Session variations that hides all the data fields in a single blob.
--
Eric Hammond
|