[SPAM] Re: [mod_python] Problem with caching

Dave Britton dave at davebritton.com
Sat Apr 4 09:49:03 EDT 2009

Use a multiuser database to hold the persistent information (MySQ or
sqlite). This is the only way you can insure that shared data, ie. data that
is intentionally passed between users, where (as in your example) what user
2 sees depends on what user 1 did, and what he does matters to the next page
load of what user 1 sees. Pickling, text files, and web server memory are
not up to the task, they are simply not designed for that across-use,
across-pageload data sharing. It's why god invented relational databases. No
wait, that's Codd.
----- Original Message -----
From: "Aaron Scott Hildebrandt" <aaron.hildebrandt at gmail.com>
To: <mod_python at modpython.org>
Sent: Friday, April 03, 2009 6:15 PM
Subject: [mod_python] Problem with caching

> This is my first time working with mod_python. One thing that I wasn't
> prepared for was dealing with persistence. I have an app that I'm
> trying to make work through mod_python, but everything goes to hell
> the moment there's multiple users.
> The way it's supposed to work is like this:
> The page is accessed. A number of variables are loaded. The user
> changes some of the variables, the changes are saved to a pickled
> file. The next time the user loads the page, those saved variable
> values are loaded back in.
> The problem is, as soon as the variables have been changed, if anyone
> accesses the page in the near future, they'll see those changed
> variables. Here's where it really starts driving me insane: a lot of
> the time, that second user will see the changed variables even if he
> has his own pickled file that has been loaded and was supposed to
> overwrite them.
> For example:
> I have a file with the variable "x = 0". A user changes the value to
> "x = 5", and that change is saved to a pickled file (tied to a session
> ID).
> A second user accesses the page, where the value is now "x = 5". He
> changed the value to "x = 10". This is saved to his own pickled file.
> The first user returns to the site. Since he's returning, his pickled
> file, with "x = 5", is loaded. Except, when he looks at the data, he
> sees "x = 10", even though that variable was supposed to have been
> changed to "5" when his file loaded.
> A more direct code example:
> The module lab.game has the class InitGame, which contains "daemons =
> {}". There's an instance of this class called "settings".
> A user runs the code, resulting in some values in "daemons":
> "{'berry2': 3, 'berry3': 5, 'berry1': 7}". These are pickled. The next
> user runs the code. I put this in to make sure "daemons" is getting
> reset:
>         req.write(str(lab.game.settings.daemons))
>         del lab.game.settings
> try: req.write(str(lab.game.settings.daemons))
> except: req.write("failed")
>         lab.game.settings = lab.game.InitGame()
>         req.write(str(lab.game.settings.daemons))
> Okay, that should wipe out any of the values and leave us with a clean
> slate, right? But no, it doesn't. This is the output:
>         {'berry2': 3, 'berry3': 5, 'berry1': 7}failed{'berry2': 3,
> 'berry3': 5, 'berry1': 7}
> So, even if I try deleting the variable itself, the moment I try to
> reinitialize it, the old values return.
> Does anyone know what I'm doing wrong, or if there's any way I can
> just kill mod_python's persistence altogether?
> Thanks,
> Aaron
> --
> Aaron Scott Hildebrandt
> andcuriouser.com
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list