in reply to Re^3: mod_perl and cache?
in thread mod_perl and cache?

I've been doing some more experements... and found something odd... it seems that apache itself may be caching it and sending it out... or at least the subs that IT calls.

I've added some output commands to certain functions, and it seems they are not always being called, even though, by rights, they should be. I'm uploading my current code to my scratchpad, take a look at the sub 'calendar' if you would... it has code that should output the current value. Yet when the month I request is '5', and it is showing '9' in my browser, the text file also shows September. Yet the arguments I have it print out show '5', and if I hit refresh after 5 minutes, it shows up as may, and the text file updates.





My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

Replies are listed 'Best First'.
Re: Re^4 (Third Time): mod_perl and cache?
by perrin (Chancellor) on Mar 03, 2003 at 18:46 UTC
    Your problem is that you are creating closures in your script. These are not a big problem under CGI because the interpreter exits every time, but under Apache::Registry you have to follow better progamming practices.

    Look at your login sub. You use the variable %ARGS in it, but don't pass it to the sub. You are taking advantage of the fact that %ARGS is declared in a higher scope and is thus visible to your subroutine. However, after the first time this gets executed the %ARGS used in the login sub is private and will no longer change.

    To fix this, you need to explicitly pass all variables to your subs. Instead of saying &login, say login(\%ARGS) and then read that in at the beginning of the login sub. This is a good programming practice, and you should be doing it anyway.

    Note that all of this is explained in the documents that merlyn pointed out to you in the very first post in this thread. You can also read about it in the mod_perl guide.

      Would I need to do the same with %session and $DBH, not to mention the Apache::Request object and the other "globals"?



      My code doesn't have bugs, it just develops random features.

      Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

        Yes. You should not refer to any lexical variables defined outside the scope of the current sub. Try to code your subs so they are portable enough to be moved to a separate module without changing their code.
Re^5: mod_perl and cache?
by Aristotle (Chancellor) on Mar 03, 2003 at 13:02 UTC
    As I said, I'm afraid I'm stumped.. I've done a bunch of CGI programming but not any mod_perl work yet (I'll get around to it one day, I swear..). Maybe one of our resident mod_perl druids can help if you repost this question as a new SOPW?

    Makeshifts last the longest.