From: Bill K. <bi...@ka...> - 2002-11-27 22:03:08
|
> > While it is true that you can't guarantee that > > subsequent requests will be served by the same Apache process, > > do certainly do know that all requests will be served by a > > process that has used the module, and hence initialized the > > array. What is the difficulty here? > >Bill's point is: if you put the data in a (page_)session or similar you can >share the global vars over all processes. Right. I was assuming that it's more important that the array data be consistent for a given session than for a given Apache process. The Perl interpreter must keep a separate copy of each data object in the module in each Process; Perl does not share simple data objects between processes (that is, not without using something like Storable, or shared memory, or a database). I suggested putting the array in a Session as a convenient way of making it persistent between processes. The Session mechanism is already present in every PageKit application, so there shouldn't be any need to create a new mechanism. Unless, I suppose, we want one instance of the array to be shared by all sessions. Then I think we should put it in a database, or into a Storable object, and then we need to manage concurrent access using a semaphore or file lock or something. You can certainly use an "our" global in the module, but we can't depend on seeing any changes to the values in the array on subsequent requests, because there's a different copy of that array in each Apache process. This is not a problem if we use the array in a static way, like as a lookup table or something. As long as our sessions make no changes to the array after initialization, it's safe to use it as a global. Wrapping it in an access function is an object-oriented style thing. It's not strictly required, but it helps to encapsulate the array behind a layer of abstraction. This is done for all other members of the Model superclass, so I'd be inclined to do the same thing with new members. This is getting further and further away from Anton's question. :-) But I think it's a useful discussion. Regards, Bill Karwin |