in reply to CGI::Application under FastCGI (Guru advice needed)

What I found out is that this approach executes cgiapp_init() and setup() on *every* request (which isn't desireable as I load my templates there, establish caches etc and these steps should run only once!).

CGI::App definitely needs to get re-initialized for each request. Even if you could find a way to work-around the problems you've found so far you'd end up getting burned again the first time you tried to use a plugin that needed per-request initialization.

So, instead of hacking CGI::App, hack your code. In your setup() you could do something like:

our $INIT_DONE; unless ($INIT_DONE++) { # do some cache init, or whatever ... }

That way you can do your one-time-only initialization in your setup and it will only happen the first time through.

-sam

Replies are listed 'Best First'.
Re^2: CGI::Application under FastCGI (Guru advice needed)
by isync (Hermit) on Nov 28, 2007 at 23:30 UTC
    Thanks for your idea! You comment made me decide for this design!
    Actually I saw this flag-todo-done approach in another C::A::Plugin module yesterday and thought it is an ugly hack. I still hoped there was a way to do it elegantly...

    BTW: Since I switched to C::A (to finally get cgi right, as they said) it was just a trial of hacks and tricks to get it working like my old homebrewn framework. Mmh. I shouldn't complain...
      Too ugly? Perhaps - beauty is in the eye of the beholder. A "cleaner" way to handle one-time cache setup is by using the singleton object pattern. It's more code, but you won't have to see anything "ugly" in your C::A sub-class.

      -sam