You will have to track the age of the session variable yourself. In real Python code, it might look something like this:
from datetime import datetime, timedelta
request.session['x'] = dict(dt=datetime.now(), value='something')
MAX_AGE = timedelta(seconds=240)
if ('x' in request.session and datetime.now() - request.session['x']['dt'] > MAX_AGE):
del request.session['x']
It is also possible to store your value in a cookie depending on what data and its size.
source
share