This is a discussion on RE: Apache::Session: can I have a "date" in session - modperl ; Another solution would be to use a CleanUpHandler and execute the SQL to flush the old sessions then. The cleanup would happen and the users wouldn't notice the load (the cleanUpHandler is executed after the content is page content is ...
Another solution would be to use a CleanUpHandler and execute the SQL to
flush the old sessions then. The cleanup would happen and the users
wouldn't notice the load (the cleanUpHandler is executed after the
content is page content is sent to the user).
From: Cees Hek [mailto:email@example.com]=20
Sent: Thursday, April 27, 2006 10:38 AM
Cc: Mod_Perl Mailing List
Subject: Re: Apache::Session: can I have a "date" in session
On 4/27/06, Igor Chudov
> I run algebra.com 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"
NEW.lm :=3D ''now'';
CREATE TRIGGER update_session_lm_trig
BEFORE UPDATE ON sessions
FOR EACH ROW
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.