[mod_python] Date persistence accross connections.

David Higgs drh9296 at ritvax.rit.edu
Thu Feb 13 22:20:30 EST 2003


Stefan C. Kremer wrote:
 > Thanks for the reply Greg.  Actually I'm in the process of writing my own
 > session management tool (I looked at a few others and none of them really
 > suited my needs; plus I wanted to do it myself for the learning
 > experience).  So now I'm trying to figure out what my options are for
 > implementing persistent data.  Right now I'm identifying my session by
 > means of a cookie, so that part's not a problem.  My challenge now 
is, how
 > to associate more data with the cookie (session) in a way that persists
 > accross http requests.
 >
 > The three options I'm working with right now are:
 >
 > (1) just store in the info in the global namespace, keyed on the 
cookie.
 > This seems to me to be the simplest, and fastest solution.  The drawbacks
 > are that queries that go to a different process won't have access to my
 > data.  Now that httpd is threaded, this happens much less often. In fact,
 > it seems to only occur when I explicitly restart apache or reboot my
 > machine (which is basically never since I don't run Windows and have a
 > UPS).
 >
 > (2) Save it to a file.  This is slow, but otherwise would work fine if I
 > implement appropriate file locking.
 >
 > (3) Send it via a socket to another process which all mod_python 
processes
 > share.
 >
 > (4) Some combination of (1) with (2 or 3), which writes the data away 
and
 > only retrieves it from (2,3) if its not in the local namespace.  I'm not
 > sure how much I will gain from not retrieving data from (2,3) most of 
the
 > time.
 >
 > Are there any good options which I have overlooked?  Does my 
evaluation of
 > the alternatives seem sound?  Any suggestions or comments.
 >
 > Thanks for any advice anyone wants to pass my way.
 >
 > 	-SK

How about storing stuff in a database?

MySQL (and many other DBs) have very usable python interfaces; getting 
and adding them to your build should be pretty simple.

You'll get all the persistence of storing to a file, but with added 
data-gathering functionality and no need to worry about locking (the DB 
should handle this for you).

The only difficulty is that you will probably want to store data in a 
DB-useable format - aka not by storing pickled objects.

--david




More information about the Mod_python mailing list