mod_perl and global %Live_Objects not being initialized

[prev] [thread] [next] [Date index for 2004/11/15]

From: Andy Grundman
Subject: mod_perl and global %Live_Objects not being initialized
Date: 21:40 on 15 Nov 2004
I am running Class::DBI under mod_perl.  One of my pages displays a 
simple form for the user to update.  The form data is populated through 
Class::DBI of course, and saved using update().

I have one copy of my Class::DBI objects in each Apache child.  Each one 
of these objects maintains an object index in the global variable 
%Live_Objects.  Since this variable is never initialized by default, the 
object index is maintained between requests, causing stale data to be 
returned instead of forcing a fresh SELECT from the database.  In a CGI 
application the variable will never contain any data, but in mod_perl 
the data is left over from the previous request.

1. Load the form several times, populating several Apache children with 
data from the database.
2. Update the form.  One of the children will save new data to the 
database and update its internal data correctly.
3. Refresh the form.  Chances are a different Apache child will display 
the form, using the outdated data from #1.
4. Refresh some more, eventually you will see the correct data from the 
one Apache process from step 2 with correct data.

I solved this by adding a call to $obj->clear_object_index() right after 
creating my Class::DBI object.  That method sets %Live_Objects = (), 
which properly clears out any old data in mod_perl.

I think you may want to always initialize the %Live_Objects to ().  This 
should be fine for a normal CGI application, since these 2 statements 
are technically the same in CGI but very different in mod_perl:
my %Live_Objects;
my %Live_Objects = ();

-Andy

(message missing)

mod_perl and global %Live_Objects not being initialized
Andy Grundman 21:40 on 15 Nov 2004

Re: mod_perl and global %Live_Objects not being initialized
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 03:02 on 19 Nov 2004

Generated at 17:31 on 15 Feb 2005 by mariachi v0.52