开发者

Cleaning a session variable periodically without cleaning session

开发者 https://www.devze.com 2023-03-31 02:09 出处:网络
In Django, is it possible to 开发者_开发技巧clean a session variable periodically without cleaning whole session?Depending upon the session manager, it might be possible but difficult.

In Django, is it possible to 开发者_开发技巧clean a session variable periodically without cleaning whole session?


Depending upon the session manager, it might be possible but difficult.

If you are using database backed sessions, you could scan the table, parse the base64 encoded data and delete the variable you want cleaned.

If you must do this, I would either extend the sessions system with a custom mod or store the variable independently somewhere I could easily flush it.


Two Approaches

set_expiry time of session and deleting it periodically can be helpful

SESSION_COOKIE_AGE = 5 * 60 #session expiry time (5 mins)

another way as Rob suggested, playing with session data based on session key.

from django.contrib.sessions.models import Session
from django.contrib.sessions.backends.db import SessionStore
sessionid = Session.objects.get(session_key=123f4b3106c740c1a54970a8b611111)
session_data = sessionid.get_decoded()
0

精彩评论

暂无评论...
验证码 换一张
取 消