On Mon, May 7, 2012 at 7:48 AM, M Oklah <okla...@googlemail.com> wrote:
>
> Hello,
>
> Is it possible to hook into Django so that a user defined callback method is
> executed each time a session expires?
>
>
> Thanks,
>
> -Moe
>

Yes/no/maybe. Depends what you want to do.

First of all, nothing happens when sessions 'expire'. I say 'expire',
because nothing actually changes. The session has an expiry date, and
when you try to use a session after its expiry date has passed, you
will get a new session.

Another thing to note is that Django does not clean expired sessions
by default. Expired sessions will live forever* in the backend. Django
provides a management command that you can run that cleans expired
sessions from the session backend.

If you use the database session backend however, then sessions are
simply models. You can attach signals to model deletion, and if you
clean your session backend frequently, then your signal will get
called for each expired session.

It won't happen the moment your session expires, only when the session
is deleted. That might be enough for you, it might not.

Cheers

Tom

* Not forever. Until a new session key collides with an existing
(expired) session.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to