0

In pset7 code in application.py there is this snippet of code:

if app.config["DEBUG"]:
    @app.after_request
    def after_request(response):
        help(response.headers)
        response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
        response.headers["Expires"] = 0
        response.headers["Pragma"] = "no-cache"
        return response

I already know that this function is called everytime the server responses to the client's computer. And this function changes the header of the response object but...

1) In the documentation that i found:(http://werkzeug.pocoo.org/docs/0.12/datastructures/#werkzeug.datastructures.Headers) there is nothing about this keywords: "Cache-Control", "Expires" or "Pragma". Where can i find a full list of this keywords?

2) The cache is a some data that computer uses a lot, but how can i the server change or handle the cache of my client? Isn't that strange? What exactly does that function do to my client's cache?

1 Answer 1

1

Those are HTTP-Headers. The app uses them to tell the HTTP client (your browser) not to cache the response (otherwise the browser might try to reuse a response instead of doing the same request again). This is especially useful in dev environments (hence the test for "DEBUG" config), where you want a changed content to be applied instantly. If the browser was allowed to cache, you might have to wait for the cache to time out.

In production environments, you would want the browser to cache static content, though, for a reasonable amount of time. How long depends on the maximum duration you can tolerate old content after you've pushed new. Even with dynamically generated content, certain information might be ok to be outdated for an hour or so, if this helps reduce server load.

1
  • Thank you very much for the answer and the site. :D Commented Oct 17, 2017 at 11:24

You must log in to answer this question.

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