perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cees Hek" <>
Subject Re: Apache::Session: can I have a "date" in session
Date Thu, 27 Apr 2006 15:38:25 GMT
On 4/27/06, Igor Chudov <> wrote:
> I run with a few thousand registered users and a lot more
> unregistered. I use Apache::Session to store their session info. Right
> now I clean sessions every month. I would like to be smarter and clean
> sessions based on date information (ie remove sessions that are more
> than 3 weeks old).
> Can I have a date as a relational column in the sessions table?
> I know that I could maintain a date in the session data blob, but, it
> is expensive to use that for a few reasons.

You can have the database do all that for you using a trigger (if your
database suports it).  I have used PostgreSQL in the past to do the

CREATE TABLE sessions (
   id varchar(32) NOT NULL PRIMARY KEY,
   a_session text NOT NULL,
   lm timestamp with time zone DEFAULT now()
CREATE FUNCTION update_session_lm() RETURNS "trigger"
   AS '
     NEW.lm := ''now'';
   LANGUAGE plpgsql;

CREATE TRIGGER update_session_lm_trig
   BEFORE UPDATE ON sessions
   EXECUTE PROCEDURE update_session_lm();

The deleting the sessions becomes a simple SQL statement against the
lm column.  And this requires no code changes as everything is handled
in the database.

There is always a trade off though.  This means more load up front
when the sessions are created and/or altered.  The database has to do
slightly more work on each request to make the expiring of sessions
easy for you in the end.



View raw message