perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Schout <msch...@gkg.net>
Subject Re: cleaning old Apache::Session's
Date Fri, 02 Jun 2000 00:25:58 GMT
On Fri, Jun 02, 2000 at 09:26:45AM +1000, Adam Cassar wrote:
> I was wondering how people are clearing out old Apache::Session's
> 
> No timestamp is used on the fields used by Apache::Session, so how do
> we clear the old sessions? 
> 
> I am not talking about the delete() method to remove a session, as that
> presumes that a user will always leave your site via pre-defined access
> points.

As was mentiuoned, TMTOWTDI, but for postgresql, you can just do:

CREATE TABLE sessions (
  id VARCHAR(32) NOT NULL,
  ts TIMESTAMP NOT NULL DEFAULT NOW(),
  a_session TEXT,
  PRIMARY KEY (id)
);

Which works.

Another equivalent solution would involve setting up a "view" on a different
table abd setting up RULES that update the timestamp.  E.g.:

CREATE TABLE session_data (
    id CHAR(32) NOT NULL,
    ts TIMESTAMP NOT NULL,
    a_session TEXT,
    PRIMARY KEY (id)
);

CREATE VIEW sessions AS SELECT id,a_session FROM session_data;

CREATE RULE sessions_update AS ON UPDATE TO sessions
    DO INSTEAD
    UPDATE session_data SET
           id = NEW.id,
           a_session = NEW.a_session,
           ts = CURRENT_TIMESTAMP
     WHERE id = OLD.id;

CREATE RULE sessions_delete AS ON DELETE TO sessions
    DO INSTEAD
    DELETE FROM session_data
          WHERE id = OLD.id;

CREATE RULE sessions_insert AS ON INSERT TO sessions
    DO INSTEAD
    INSERT INTO session_data
                (id, a_session, ts)
         VALUES (NEW.id, NEW.a_session, CURRENT_TIMESTAMP);

This works too.  And has the added nifty feature that "sessions" looks exactly
like what Apache::Session expects to find.  

I'm sure there are other ways to do it (plpgsql, triggers come to mind) for
postgresql.  As I said, TMTOWTDI.

I'm sure nearly every dbms out there can use some variant of one of the above
two methods...  You'll just have to adapt it for your particular DBMS.

Mike

Mime
View raw message