Clean server-side session files - Flask-Session using filesystem

后端 未结 1 2022
梦毁少年i
梦毁少年i 2021-02-10 04:54

I chose to use a server-side session management with Flask using Flask-Session.

I store the data using filesystem and as expected, these

相关标签:
1条回答
  • 2021-02-10 05:50

    As Danila Ganchar commented, using PERMANENT_SESSION_LIFETIME allows to control the session expiration time.

    Flask-Session use the same builtin config than Flask itself (related to session). From Flask-Session doc:

    The following configuration values are builtin configuration values within Flask itself that are related to session. They are all understood by Flask-Session, for example, you should use PERMANENT_SESSION_LIFETIME to control your session lifetime.

    Example:

    # __init__.py
    
    from flask_session import Session
    from datetime import timedelta
    
    app.config['SESSION_PERMANENT'] = True
    app.config['SESSION_TYPE'] = 'filesystem'
    app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=5)
    
    # The maximum number of items the session stores 
    # before it starts deleting some, default 500
    app.config['SESSION_FILE_THRESHOLD'] = 100  
    
    app.config['SECRET_KEY'] = config.SECRET_KEY
    sess = Session()
    sess.init_app(app)
    
    0 讨论(0)
提交回复
热议问题