I was wondering if somehow could help me understand the following snippet of code from the pset distribution code:

# Ensure responses aren't cached
def after_request(response):
    response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
    response.headers["Expires"] = 0
    response.headers["Pragma"] = "no-cache"
    return response

# Configure session to use filesystem (instead of signed cookies)
app.config["SESSION_FILE_DIR"] = mkdtemp()
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"

What I don't understand is, in what circumstances would I need to disable caching of responses or make sure that sessions are stored on the local filesystem rather than in cookies? Especially in light of my final project, where I'd like to try to create a Web application using Flask.

Thanks a lot in advance!


I'm not certain, but I'd venture to guess that it's for development purposes. You don't want caching to happen because your latest changes may not be reflected on the page; and as for storing the session locally, it is likely because you're testing multiple users and cookies might not behave as expected, you'd possibly have to deal with multiple cookies since multiple accounts exist on 1 browser.

  • Ah, that makes sense. Thanks Allan! Jul 26 '18 at 23:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .