0

I have a simple web app running behind nginx using flask+gunicorn and somewhere along the line a stale version of the page is being cached. My nginx config has add_header Cache-Control no-cache; and proxy_buffering off; in the location for the proxy pass. I did some searching and found that gunicorn itself does not cache anything. My application also does not cache anything, or at least I haven't written it to.

server { listen 80; server_name mywebsite.com; location / { add_header Cache-Control no-cache; proxy_pass http://127.0.0.1:6789; proxy_set_header Host $host; proxy_buffering off; } }

That's the nginx config I am using and gunicorn was launched with gunicorn -b 127.0.0.1:6789 -w 5 app:app and no special configs have been set for it.

Any help diagnosing the problem would be great. Thanks!

edit: Here are the response headers from a request returning the stale page.

Age: 0 Cache-Control: no-cache Connection: Keep-Alive Content-Encoding: gzip Content-Type: text/html; charset=utf-8 Date: Mon, 27 Jun 2016 14:27:29 GMT Server: nginx/1.8.0 Transfer-Encoding: chunked

Uwe Keim
  • 2,420
  • 5
  • 30
  • 47

2 Answers2

0

Static stuff like sending files?

"return send_file('mypage.html')"?

That type of oneliners where cached for me by default in flask.

Solution was: app.config.update(SEND_FILE_MAX_AGE_DEFAULT=0)

I got a setup where I only feed back html pages in flask (they contain angular so I don't do any code in flask. Gunicorn + nginx for hosting it and nginx for non-html statics (js, css, fonts images etc). Nothing caches after that option was set, so unlikely it is your gunicorn or nginx (but who knows, Im no expert on them and perhaps you got some other version than I, where they did cache). So could be your flask, depending what you do with it. I run 4 gunicorn workers.

-1

I've concluded that since gunicorn creates worker threads that one or more don't have working price updating threads and get stuck with stale results. I'm now running gunicorn with only one worker, which seems to defeat the purpose of using it but whatever.