i’ve run into a couple of spots where it would be nice to have a universally
accessabe cgi instance, but i do not know if this is safe, especially
considering that mod_ruby can persist globals across requests. could a global
cgi object bleed over into unexpecting requests? anyone know what kind of
effect something like this would have? on the other hand, what effect does it
have to have many CGI.new’s in the same script? that’s another alternative.
thanks,
tom
···
–
tom sawyer, aka transami
transami@transami.net
.''.
.''. . *''* :_\/_: .
:_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'.
.’’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:’.:::. | ’ ‘’ * ‘.’/.’ (/’.’:’.’
: /\ : ::::: = / -= o =- /)\ ’ *
’…’ ‘:::’ === * /\ * .’/.’. ‘._____
* | … : |. |’ .—"|
* | _ .–’| || | _| |
* | .-’| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /"\ | '-."". ‘-’ ‘-.’ '` |.
Sounds like a Singleton pattern may be useful. Same effect, no ugly
globals.
Gavin
···
On Wednesday, January 8, 2003, 12:17:34 PM, Tom wrote:
i’ve run into a couple of spots where it would be nice to have a
universally accessabe cgi instance, […]
This is actually what Narf does - which you are welcome to check out
of CVS (http://narf-lib.sourceforge.net). Check out the docs here:
RDoc Documentation
I’m in the process of prepping it for a release, so the docs may not
be fully debugged.
-Tom
···
On Wed, Jan 08, 2003 at 10:17:34AM +0900, Tom Sawyer wrote:
i’ve run into a couple of spots where it would be nice to have a universally
accessabe cgi instance, but i do not know if this is safe, especially
considering that mod_ruby can persist globals across requests. could a global
cgi object bleed over into unexpecting requests? anyone know what kind of
effect something like this would have? on the other hand, what effect does it
have to have many CGI.new’s in the same script? that’s another alternative.
thanks,
tom
–
tom sawyer, aka transami
transami@transami.net
.''.
.''. . *''* :_\/_: .
:_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'.
.‘’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:‘.:::. | ’ ‘’ * ‘.'/.’ (/’.‘:’.’
: /\ : ::::: = / -= o =- /)\ ’ *
‘…’ ‘:::’ === * /\ * .‘/.'. ‘._____
* | … : |. |’ .—"|
* | _ .–’| || | _| |
* | .-‘| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /“\ | '-.”". ‘-’ ‘-.’ '` |.
i’ve run into a couple of spots where it would be nice to have a
universally accessabe cgi instance,
Hm, can you explan where/how this can be useful? In Samizdat, I cache db
connection and parsed yaml config in singleton classes, and it gives me
great speed-up, too, but I don’t see what CGI caching can add?
but i do not know if this is safe, especially considering that
mod_ruby can persist globals across requests.
The question is, does it persist globals (or singleton classes) across
apache processes, i.e. across parallel connections possibly from
different clients?
I also have another second thought that I didn’t have time to play with
yet: there are other Ruby/CGI implementations beside mod_ruby, is it a
good idea to depend on mod_ruby behaviour, or is it worth developing
cross-implementation web application?
···
On Wed, Jan 08, 2003 at 10:17:12AM +0900, Tom Sawyer wrote:
–
Dmitry Borodaenko
ah yes, that clears it up a bit. that would work fine if… my fear is one of
multiple users accessing my app and winding up with one anothers cgi
instance, so there’s where i have been unclear: each user will receive there
own space. yes? no sharing globals or class variables (@@s) between them? i
imagine that must be the case, though i do not know how mod_ruby handles this
(based on requesting ip?) yet still persisting these for a single user.
anyway i just want to be sure that implemenating a Singleton pattern for cgi
will not cause any unforseen problems.
thanks Gavin,
tom sawyer, aka transami
transami@transami.net
.''.
.''. . *''* :_\/_: .
:_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'.
.‘’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:‘.:::. | ’ ‘’ * ‘.'/.’ (/’.‘:’.’
: /\ : ::::: = / -= o =- /)\ ’ *
‘…’ ‘:::’ === * /\ * .‘/.'. ‘._____
* | … : |. |’ .—"|
* | _ .–’| || | _| |
* | .-‘| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /“\ | '-.”". ‘-’ ‘-.’ '` |.
···
On Tuesday 07 January 2003 06:24 pm, Gavin Sinclair wrote:
Singleton pattern
okay, i’m implementing singleton pattern for CGI. simple appraoch:
require 'singleton'
class CGI
include Singleton
end
now CGI.new dosen’t work and one must use CGI.instance. but is there a way
just to redefine #new to do the same thing rather than having a different
method? i’d rather not have to go around changing #new to #instance? seems
like i’ve delt with this before but i don’t remember what i came up with.
also perhaps i should subclass CGI for this and create CGISingleton rather
then directly altering CGI itself.
some thoughts on the best approach to take would be greatly welcome. thanks.
-transami
.''.
.''. . *''* :_\/_: .
:_\/_: _\(/_ .:.*_\/_* : /\ : .'.:.'.
.’’.: /\ : ./)\ ‘:’* /\ * : ‘…’. -=:o:=-
:/:’.:::. | ’ ‘’ * ‘.’/.’ (/’.’:’.’
: /\ : ::::: = / -= o =- /)\ ’ *
’…’ ‘:::’ === * /\ * .’/.’. ‘._____
* | … : |. |’ .—"|
* | _ .–’| || | _| |
* | .-’| __ | | | || |
.-----. | |’ | || | | | | | || |
__’ ’ /"\ | '-."". ‘-’ ‘-.’ '` |.
···
okay, i’m implementing singleton pattern for CGI. simple appraoch:
require 'singleton'
class CGI
include Singleton
end
now CGI.new dosen’t work and one must use CGI.instance. but is there a way
just to redefine #new to do the same thing rather than having a different
method? i’d rather not have to go around changing #new to #instance? seems
like i’ve delt with this before but i don’t remember what i came up with.
#new and #instance mean different things. I think you should avoid
confusing them.
also perhaps i should subclass CGI for this and create CGISingleton rather
then directly altering CGI itself.
That would be better, I think.
some thoughts on the best approach to take would be greatly welcome. thanks.
I can’t think of any disadvantage to the subclassing approach.
Gavin
···
On Wednesday, January 8, 2003, 1:45:06 PM, Tom wrote: