Set no-cache headers on page while firstRun is True

This commit is contained in:
Gina Häußge 2015-07-09 09:28:31 +02:00
parent 163100bd44
commit f1afb70b47

View file

@ -21,7 +21,9 @@ import logging
_logger = logging.getLogger(__name__)
@app.route("/")
@util.flask.cached(refreshif=lambda: util.flask.cache_check_headers() or "_refresh" in request.values, key=lambda: "view/%s/%s" % (request.path, g.locale))
@util.flask.cached(refreshif=lambda: util.flask.cache_check_headers() or "_refresh" in request.values,
key=lambda: "view/%s/%s" % (request.path, g.locale),
unless_response=util.flask.cache_check_response_headers)
def index():
#~~ a bunch of settings
@ -240,12 +242,13 @@ def index():
#~~ prepare full set of template vars for rendering
first_run = settings().getBoolean(["server", "firstRun"]) and (userManager is None or not userManager.hasBeenCustomized())
render_kwargs = dict(
webcamStream=settings().get(["webcam", "stream"]),
enableTemperatureGraph=settings().get(["feature", "temperatureGraph"]),
enableAccessControl=userManager is not None,
enableSdSupport=settings().get(["feature", "sdSupport"]),
firstRun=settings().getBoolean(["server", "firstRun"]) and (userManager is None or not userManager.hasBeenCustomized()),
firstRun=first_run,
debug=debug,
version=VERSION,
display_version=DISPLAY_VERSION,
@ -260,10 +263,20 @@ def index():
#~~ render!
return render_template(
import datetime
response = make_response(render_template(
"index.jinja2",
**render_kwargs
)
))
response.headers["Last-Modified"] = datetime.datetime.now()
if first_run:
response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "-1"
return response
def _process_template_configs(name, implementation, configs, rules):