caching data in a module

2006-02-07 Thread Daniel McBrearty
Hi all I have some multilingual pages running on mysql/modperl. I'm thinking that certain text will be retrieved again and again from the db, hence I'm thinking about caching it in a hash. There is alreaday a specific method I get that retrieves these values so just a rewrite of that method would

Re: caching data in a module

2006-02-07 Thread Jonathan Vanasco
if it is in the hash at startup, all the children will access that hash and share it. if it written to after startup.pl, use memcached On Feb 7, 2006, at 1:31 PM, Daniel McBrearty wrote: that any memory that gets written to will be seen as dirty, and therefore not shared. But if it is only

Re: caching data in a module

2006-02-07 Thread Daniel McBrearty
Thanks Jonathan Just to be clear - the hash and the method to init it are declared and defined in MyModule like this: {  my $hash = 0; sub init {   # fill in the hash completely } sub getValue {   # get stuff (die if $hash == 0, because not init'd) } } in startup.pl is only use MyModule (); M

Re: caching data in a module

2006-02-08 Thread Daniel McBrearty
Hi I got this working fine on my dev machine without too much trouble. But when I tried it on my production server things went astray. On closer examination, it seems that in both cases the memory cache is not being shared between processes. The cahe is not that big though (a few hundred k perhap

Re: caching data in a module

2006-02-08 Thread Daniel McBrearty
OK, I fixed it. Classic modperl mistake, I guess ... The my $cache; is not shared because the subs look like named inner subs to Apache::Registry. The solution is to do use vars '$cache'; It's all in chapter 4 of "writing apache modules with perl and c" (stein/maceachern), if anyone ever wan

Re: caching data in a module

2006-02-08 Thread Perrin Harkins
Daniel McBrearty wrote: OK, I fixed it. Classic modperl mistake, I guess ... The my $cache; is not shared because the subs look like named inner subs to Apache::Registry. The solution is to do use vars '$cache'; I can't say for sure without seeing your code, but this doesn't sound right.

Re: caching data in a module

2006-02-08 Thread Daniel McBrearty
Thanks. Well, here is the code (slightly edited) package Sitetext; {     my $sitetext_cache = {};     sub init     {     print "Sitetext::init\n";     my $all = getAll();     foreach $st (@$all)     {     # ... fill in the cache. This is definitely OK.     } #pri

Re: caching data in a module

2006-02-08 Thread Daniel McBrearty
I don't know if this is connected, but I noticed init was getting called TWICE on a restart. I turned of PerlFreshRestart and now it just happens once. Can't quite see the connection, but maybe it is related ...On 2/8/06, Daniel McBrearty <[EMAIL PROTECTED] > wrote:Thanks. Well, here is the code (

Re: caching data in a module

2006-02-08 Thread Perrin Harkins
On Wed, 2006-02-08 at 21:03 +0100, Daniel McBrearty wrote: > I don't know if this is connected, but I noticed init was getting > called TWICE on a restart. I turned of PerlFreshRestart and now it > just happens once. > > Can't quite see the connection, but maybe it is related ... That probably is

Re: caching data in a module

2006-02-09 Thread Daniel McBrearty
the extra braces are just a way of keeping $sitetext_cache private to methods in the block.I haven't tried the other variations though - I will at some time. It seems to be flying happily with the use vars version though. On 2/9/06, Perrin Harkins <[EMAIL PROTECTED]> wrote: On Wed, 2006-02-08 at 21