Opened 17 years ago

Closed 16 years ago

Last modified 16 years ago

#6791 closed (fixed)

Cached DB Session Backend

Reported by: jhenry Owned by: Jacob
Component: contrib.sessions Version: 1.0
Severity: Keywords:
Cc: pytechd@…, jdunck@…, waylan@…, gabor@…, Peter Kese Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Right now, I consider the "cache" session backend to be broken, especially when used with the memcached session backend.

In a large memcached environment, servers enter and leave the memcached pool frequently. Each time this happens, the pool mapping changes and automatically logs users out (and loses their session data).

Attached is a new backend which is basically a copy of the DB session backend with a django.core.cache wrapper on accesses to the session data; all writes are write through to the database and cache and all reads come from memcache except in case of a memcache failure when it reads from the database.

Attachments (5)

cached_db.diff (2.3 KB ) - added by jhenry <jhenry@…> 17 years ago.
cached_db_with_documentation.diff (3.5 KB ) - added by mcroydon 17 years ago.
Added documentation to patch against trunk
cached_db_docs_and_tests.diff (5.5 KB ) - added by Jeremy Dunck 17 years ago.
Changed default session backend to cached_db. Changed docs to be betterer. ;-) Added tests.
cached_db_docs_and_tests-2.diff (4.7 KB ) - added by Jeremy Dunck 17 years ago.
Last patch didn't include the actual code for cached_db backend. :-/
cached_db.py (1.4 KB ) - added by Aurelio Tinio 16 years ago.
Modified cached_db.py used to work with django-1.0-final

Download all attachments as: .zip

Change History (25)

by jhenry <jhenry@…>, 17 years ago

Attachment: cached_db.diff added

by mcroydon, 17 years ago

Added documentation to patch against trunk

by Jeremy Dunck, 17 years ago

Changed default session backend to cached_db. Changed docs to be betterer. ;-) Added tests.

comment:1 by Jeremy Dunck, 17 years ago

Owner: changed from nobody to Jeremy Dunck
Status: newassigned

by Jeremy Dunck, 17 years ago

Last patch didn't include the actual code for cached_db backend. :-/

comment:2 by Jeremy Dunck, 17 years ago

After talking with Jacob, I reverted the default session backend to DB; changing the default is controversial, and this should be a simple win for interested people.

Anyway, cached_db_docs_and_tests-2.diff is the best; I somehow managed to leave cached_db.py out of my prior diff.

comment:3 by Simon Greenhill, 17 years ago

Triage Stage: UnreviewedReady for checkin

comment:4 by mrts, 17 years ago

milestone: 1.0

Looks to be in scope for 1.0.

comment:5 by Eric <pytechd@…>, 16 years ago

Cc: pytechd@… added

comment:6 by Jeremy Dunck, 16 years ago

Cc: jdunck@… added
Owner: changed from Jeremy Dunck to Jacob
Status: assignednew

comment:7 by Jeremy Dunck, 16 years ago

Owner: changed from Jacob to Jeremy Dunck
Status: newassigned

comment:8 by Jeremy Dunck, 16 years ago

Owner: changed from Jeremy Dunck to Jacob
Status: assignednew

comment:9 by Russell Keith-Magee, 16 years ago

milestone: 1.01.0 maybe

comment:10 by Russell Keith-Magee, 16 years ago

Forgot to include an explanation with the status change: This isn't a bug, it's a completely new cache backend. It's a nice-to-have, but not essential.

comment:11 by korpios, 16 years ago

milestone: 1.0 maybepost-1.0

comment:12 by korpios, 16 years ago

Cc: korpios@… added

comment:13 by korpios, 16 years ago

Cc: korpios@… removed

by Aurelio Tinio, 16 years ago

Attachment: cached_db.py added

Modified cached_db.py used to work with django-1.0-final

comment:14 by Aurelio Tinio, 16 years ago

Version: SVN1.0

Hi, thanks for the patch. It was exactly what I was looking for but had to make minor changes in order to get it to work with django 1.0. Specifically added the must_create parameter for the save method and added a flush method that passes the session_key argument for deletion.

Sorry for not posting it as a diff, just wanted to quickly put this up for anyone that might find it useful.

comment:15 by anonymous, 16 years ago

Cc: waylan@… added

comment:16 by Gábor Farkas, 16 years ago

Cc: gabor@… added

comment:17 by Peter Kese, 16 years ago

Cc: Peter Kese added

I am running a cron job every night to delete expired sessions.
How does this fit with the cached_db session store strategy?

I'd suggest to add some signals to the Session's save() and delete() functions and update the cache accordingly.

comment:18 by Jeremy Dunck, 16 years ago

I think you're talking about reaping through a database query. Just as model delete signals don't fire when doing that, cache isn't cleared when deleting cached_db from with a database query. Firing a signal per model instance is about as slow as deleting a record at a time-- it defeats the purpose of doing the query rather than looping over queryset results.

Still, mass deletes are a frequent need. I guess there could be a mass invalidation method, but I don't see a good place to do that.

comment:19 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [9727]) Fixed #6791: added a write-through cache session backend: session data is written through the cache to the database, but read from the cache for speed. Thanks to jhenry, mcroydon, and jdunck.

comment:20 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top