Issue #767 open

Replace sessions.py with something good

Robert Brewer
created an issue

The session library in CP isn't very good: it's hard to extend, partly because IMO it tries to do too much. For example, it shouldn't try to allow both eager and lazy locking. It also does too much at the class level instead of the instance level; that is, instead of instantiating a Session object per request, it should just stick all that state into cherrypy.request--it would then be free to instantiate a FileSession object per Application, rather than using class variables to manage config across requests.

Comments (4)

  1. Robert Brewer reporter

    It might also be good to move cherrypy.session to cherrypy.request.session. This would make it clear that the session is serving-scoped, and also simplify the implementation (by removing the _ThreadLocalProxy). Another solution would be to just ditch the proxy and go with cherrypy.serving.session (which the implementation already uses anyway).

  2. guest

    As this sounds like a huge overhaul of Sessions is planned, i wanted to make a suggestion: Many things, that those subclasses of cherrypy.lib.sessions.Session do, are things that would fit perfectly in a seperate interface. As many people are familiar with the python-memcached API, i want to peopose a CacheInterface layer to provide just that.

    The problem with MemcachedSession (and Session) is, that it does many things that memcached already does, like taking care about expiration. In the current state, whether a session is expired or not, is always tested twice.

    The file I attached is not meant as a patch, but as an proof-of-concept, e.g. DatabaseCache is meant to make use of an abstraction-layer like SqlAlchemy/Storm/etc (in this case I use a hand-crafted one).

    I would be happy to hear any thoughts on this.

  3. Log in to comment