glwtta has asked for the wisdom of the Perl Monks concerning the following question:

I am in need of the Monks' experience once again,

Simple question really - I am working on a web application using mod_perl and I find that I am at a point where I need some session persistant data.

I am looking at CGI::Session and Apache::Session and was wondering what kind of experience people have had with the two, and which one would be recommended. And of course if there is another option that I didn't find.

A word about what I need it for - this is an internal application which does not involve any sort of personal information (in other words security is not one of my concerns); mostly what I need this for is things like passing the output of one webapp to a different app in some sort of generalized fashion, saving SQL queries built through forms so I can paginate the results, etc.

So far I haven't seen great differences between the two, if anything CGI::Session seems a bit more featureful... any words of advice?

Replies are listed 'Best First'.
Re: mod_perl and sessions
by perrin (Chancellor) on Jun 11, 2003 at 20:49 UTC
    I've never used CGI::Session so I can't comment on it, but here's one thing you should think about: a session is not the right place to cache data! If you put, for example, someone's search results into her session so that you can display them 20 at a time, and then she opens a second browser window and does another search at the same time, all hell will break loose. It's better to cache data under some canonical name (e.g. string the search parameters together to form a unique ID) and store it with something like Cache::Cache.
      Good point, except that the "sessions" in this case are not necessarily tied to "user sessions" - a new session id would be generated for each search, and embedded in the URLs to retrieve the data (I would never store these "session" ids as cookies). In fact this also allows people to share the search sessions, simply by exchanging the formatted URLs.

      Would Cache::Cache offer any additional advantages with this scenario? The way I see it, CGI::Session will also generate the ids for me (and I can use the same mechanism for storing actual user sessions, should I need them).

      (Incidentally, a few popular systems use this concept of "session" as different from an HTTP session - Lion's SRS comes to mind; so my users are quite used to the idea).

        If you make sure to generate a new ID for every search then it should work. Personally, I would just use the combined search params as an ID, but it doesn't make much difference.

        Cache::Cache offers a concept of expiration, which I think CGI::Session does as well. Cache::Cache can handle multiple namespaces for caching different kinds of things, which could be an advantage. For example, you could set different expirations or clear out all the cached data from one section without touching the other cached stuff.

Re: mod_perl and sessions
by naChoZ (Curate) on Jun 11, 2003 at 20:22 UTC