Hamzah Al-Hamadani
Hamzah Al-Hamadani

Reputation: 1

how to clear flask session filesystem

app = Flask(__name__, static_url_path="/static")
app.config["SECRET_KEY"] = os.urandom(24)
app.config["SESSION_TYPE"] = "filesystem"
app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(days=31)
app.config.from_object(__name__)

The flask up configuartion is mentioned above. my SESSION_TYPE is filesystem and can be changed to database if need be. I havnt tried database stored sessions so far. However for filesystem sessions when someone visits the site it stores a session in a file on the system. without deleting them it keeps storing these sessions. while i understand the file size is very small i find it annoying and not productive. How to deal with this issue? is there a way to delete said files?

I have done some research nothing useful much beside chatgpt suggesting to create a os delete function with a timer that after some said time it will be invoked and will delete the contents of the session folder. However while that is definitially possible it sounds very insufficient.

Also if you have great understanding with sessions please explain the permanant life time and what are the right ways and practices to use sessions

thank you good sir!

Upvotes: 0

Views: 130

Answers (0)

Related Questions