Mailing List Archive

"Global" or module data
Ciao!

From an Embperl page, I am creating a SELECT/OPTION widget that is
populated with the results of a database query. The content of this
database source is relatively static over time, so I would like to only
have to hit the database once, create a perl structure of the results if
it does not already exist, and store it away somewhere for subsequent
use by *all* sessions.

Is this a recommended use of the %mdat hash? Frankly, I'm hesitant to
consider a 'global' data structure such as this, but since it isn't
subject to change for the life of the Apache server children, I can't
see any problems with it hanging around for all sessions to use. I'm
just needing to craft a way to make it persist and globally available.

Suggestions welcome ...

Peace.
RE: "Global" or module data [ In reply to ]
Hi,

>
> >From an Embperl page, I am creating a SELECT/OPTION widget that is
> populated with the results of a database query. The content of this
> database source is relatively static over time, so I would like to only
> have to hit the database once, create a perl structure of the results if
> it does not already exist, and store it away somewhere for subsequent
> use by *all* sessions.
>
> Is this a recommended use of the %mdat hash?

Consider that the values in the %mdat hash are also store (by
Apache::Session) in some backend store, for example a database if you use
DBIStore. The benefit of this is, that %mdat is shared between all the
childs of Apache.

In your case I would use a normal Perl global (if you are running under
mod_perl). This is not shared between Apache childs, so you get a database
query per child, but it's much faster. Either put your global in a separate
namespace (%myvars::selection) or put the name in the %CLEANUP hash, that
will tell Embperl not to undef this hash at the end of the request.

Gerald


-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------