Whiz Kid has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

I sought an answer in the archives, but did not find anything quite right. Could mean my searching stinks. :)

I'm working through a web/backend code set that has been dormant for a few years, mainly migrating from mod_perl 1 to 2, but also looking at some other cleanup.

The code has a global configuration flat file containing config data which changes rarely, but must be changeable without code changes. The configuration is shared amongst a number of CGI scripts as well as back-end daemon processes.

I'm interested in instantiating a data structure in system memory to avoid performance hits reading disk in the CGI. The data structure would need to outlast any given session, which eliminates a number of solutions.

The existing implementation uses IPC::ShareLite and a shared memory segment to accomplish persisting the data.

Is there a simpler or more elegant solution?

Thanks...

  • Comment on Caching File-based Config across many sessions

Replies are listed 'Best First'.
Re: Caching File-based Config across many sessions
by sgifford (Prior) on May 01, 2007 at 03:03 UTC
    I've had good luck with Cache::Mmap and Cache::FastMmap. I've heard good things about Cache::Memcached for distributed longer-term storage, but I haven't used it. One nice thing about all of these is they have roughly the same interface, and so you should be able to switch between them without too much hassle if you decide to later on.
Re: Caching File-based Config across many sessions
by TOD (Friar) on Apr 30, 2007 at 23:58 UTC
    if you put your config-data in a hashtable there's an easy way for you:

    package MyApp::Config; use strict; use vars qw/%appdata/; %appdata = ( key_1 => value_1, [...] key_n => value_n );
    startup.pl:
    use MyApp::Config;
    later in your cgi-scripts:
    our %appdata; *appdata = \%MyApp::Config::appdata;


    -----------------------------------
    masses are the opiate for religion.

      This won't work right in mod_perl by itself since changes to the config package will require a restart of the server which the OP said he didn't want.

      What will work is doing the above with Apache::Reload. And to reduce the impact of Apache::Reload on the rest of your modules you can restrict it to just check this one config package.


      -- More people are killed every year by pigs than by sharks, which shows you how good we are at evaluating risk. -- Bruce Schneier