[Twisted-web] Session trouble

Michal Pasternak twisted-web@twistedmatrix.com
Wed, 17 Dec 2003 00:47:12 +0100


Hi,

On a page of the site I've got a form. The user enters values and submits
the form. Entered values are saved to session. If s/he gets back to the page
(=> encounters the same form), values are loaded from the session and the
form is filled with them. Everything worked okay, until I turned on caching.
Now, even if the test machine is on different subnet, the filled values are
presented to all connected users by default (eg. my friend, while testing
it, enters some data; I open a "clean" browser, without any cookies or such,
enter the page with the form - and I get the same data he entered!).

My question is simple: how do I get around this?

If I turn off caching, everything is fine - but I need caching. It speeds up
things a lot.

Is it known issue? What am I doing wrong? Where should I RTFM?

I run the site server with twistd and RPY script.

This is my RPY script:

	cache()
	import myWeb
	resource = myWeb.RootPage()

This is how I save / load session values in myWeb:

     I have declared:
     
	class IPreferences(components.Interface):
    		pass
	class Preferences(components.Adapter):
    		__implements__ = IPreferences
	components.registerAdapter(Preferences, server.Session, IPreferences)

     Then, when I'm loading/saving values from/to session, I use:

        prefs = req.getSession(IPreferences)
	
     saving values to session:
     
	prefs.foobar = 5
	
     loading values from session:
     
     	a = prefs.foobar
	
-- 
Michal Pasternak :: http://pasternak.w.lub.pl :: http://winsrc.sf.net