Django

Code

Ticket #2066 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

[patch] Make session framework backends pluggable

Reported by: hironobu@nerv.or.jp Assigned to: jacob
Milestone: Component: Contrib apps
Version: SVN Keywords: session handling
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I want a new session handler, suitable with django.contrib.auth, admin, etc... getting along with existing any modules of Django. I want session storage apart from contents database, and enhancing for load balancing and high availability. I think it is good merit for Django to have an expandable session handling system.

If there are any needs for such system, I'd like to post a patch to fulfill this feature. (...Or maybe developer team is now implementing same function, though. ...Then sorry. (_ _) )

Attachments

session.zip (3.7 kB) - added by hironobu@nerv.or.jp on 06/02/06 02:17:38.
session handler with database and memcached, prototype.
session_engines.diff (25.6 kB) - added by John D'Agostino <john.dagostino@gmail.com> on 06/18/07 02:29:05.
configurable session_engines

Change History

06/02/06 02:17:38 changed by hironobu@nerv.or.jp

  • attachment session.zip added.

session handler with database and memcached, prototype.

06/02/06 07:31:47 changed by lukeplant

Sessions in Django are already pluggable. You simply specify a different middleware and a different app in 'INSTALLED_APPS', unless I'm missing something.

Are you suggesting that your code goes into 'contrib'? (if so you will need to clean up the code e.g. remove hard coded memcached server and similar).

What are the specific enhancements that your code brings over what Django already has?

06/02/06 10:06:28 changed by adrian

From what I can tell, it seems this patch allows storage of session data in memcached instead of the database.

06/02/06 11:13:33 changed by hironobu@nerv.or.jp

Yes, adrian. Sorry for my poor explaining and dirty code...

I picked 'django.contrib.sessions.*' module, and tried to make it possible to use memcached or database selectively.

If possible, I'd like to propose "SESSION_ENGINE" element in settings.py, so that we can select session storage from it - instead of hardcoded "_type = 'memcache'", as lukeplant pointed out.

But I didn't prefer to touch so much code - any other than the module originated from 'django.contrib.sessions.*', I decided to finish within it.

This is the reason why I hardcoded it.

06/02/06 13:02:17 changed by adrian

  • summary changed from pluggable session handler to [patch] Make session framework backends pluggable.

06/29/06 00:50:53 changed by anonymous

any chance of getting this into contrib?

this will be one step do not requiring a database for django to work

FWW I just implemented the same thing (just to the cache) here  http://svn.zyons.python-hosting.com/trunk/zilbo/common/sessions/middleware.py

02/17/07 04:05:15 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Design decision needed.

06/18/07 02:29:05 changed by John D'Agostino <john.dagostino@gmail.com>

  • attachment session_engines.diff added.

configurable session_engines

06/18/07 02:36:47 changed by John D'Agostino <john.dagostino@gmail.com>

Discussion: http://groups.google.com/group/django-developers/browse_thread/thread/fd314ad62417db98/8e614855debfaee1

I'm actually +0 on this, after reading lukeplants comment.

Notes on the patch:

adds SESSION_ENGINE setting, and database, cache, file based session backends.

cache backend based on django.core.cache - although i do have code for a pure memcache session store.

to implement your own session engine, subclass SessionBase? and provide load,save,exists and delete methods

updated tests

updated docs (although they need improvement)

models.py hasn't been modified to maintain backwards capability; although all functionality is now in SessionBase?

Comments always welcome. Willing to improve the patch or answer any WTFs in the code.

08/15/07 16:05:38 changed by anonymous

A backend session framework shouldn't lose data when a memcache node goes down. I think that memcache could be used to speed up the select operations from the session, but all inserts should go to both memcache and to the db session backend.

Instead of a different backend, I would propose an extension to the existing backend to store the session data in memcache in addition for improved performance in high-read low-write situations. Perhaps a person could add an option to disable the database store if session data integrity is of no consequence and the application can tolerate logging all users out on a node failure.

08/25/07 06:06:08 changed by anonymous

I think with Session.objects.cache() method implemented, this patch becomes less attractive

09/14/07 16:51:35 changed by buriy

  • owner changed from nobody to buriy.
  • status changed from new to assigned.

09/15/07 14:34:37 changed by jacob

  • owner changed from buriy to jacob.
  • status changed from assigned to new.

09/15/07 14:34:47 changed by jacob

  • status changed from new to assigned.

09/15/07 16:29:14 changed by jacob

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [6333]) Fixed #2066: session data can now be stored in the cache or on the filesystem. This should be fully backwards-compatible (the database cache store is still the default). A big thanks to John D'Agostino for the bulk of this code.


Add/Change #2066 ([patch] Make session framework backends pluggable)




Change Properties
Action