Do not refresh on no-cache in request

Remove code that would lead to a refresh upon receiving a
'Cache-Control: no-cache' or 'Pragma: no-cache' in a request. The
purpose of these headers is to invalidate intermdiate proxy caches, not
that of an application server. A refresh in octoprint would lead to
several seconds of high CPU utilization on lower-power systems (like the
Raspberry Pi), leading to stuttering in print jobs.

It is still possible to explicitly cause a refresh by including
`_refresh` in the query parameters of a request.
This commit is contained in:
Mike Ryan committed 2019-11-21 08:48:44 -06:00
1 parent 84a99e1b53
commit 3b1874ea25
3 files changed
+7 -7

No files matched your search

+1
View File
@@ -115,6 +115,7 @@ date of first contribution):
* [Ludovico de Nittis](https://github.com/RyuzakiKK)
* [Dominik Paľo](https://github.com/DominikPalo)
* [Kelly Anderson](https://github.com/cbxbiker61)
* [Mike Ryan](https://github.com/justfalter)
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
[Daid Braam](https://github.com/daid). Parts of its communication layer and
+4 -5
View File
@@ -587,11 +587,10 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin):
There are two methods used in order to allow for caching of the actual
response sent to the client. Whatever a plugin implementation returns
from the call to its :meth:`~octoprint.plugin.UiPlugin.on_ui_render` method
will be cached server side. The cache will be emptied in case of explicit
no-cache headers sent by the client, or if the ``_refresh`` query parameter
on the request exists and is set to ``true``. To prevent caching of the
response altogether, a plugin may set no-cache headers on the returned
response as well.
will be cached server side. The cache will be emptied if the ``_refresh``
query parameter on the request exists and is set to ``true``. To prevent
caching of the response altogether, a plugin may set no-cache headers on
the returned response as well.
``UiPlugin`` is a :class:`~octoprint.plugin.core.SortablePlugin` with a sorting context
for :meth:`~octoprint.plugin.UiPlugin.will_handle_ui`. The first plugin to return ``True``
+2 -2
View File
@@ -174,8 +174,8 @@ def index():
def wizard_active(templates):
return templates is not None and bool(templates["wizard"]["order"])
# we force a refresh if the client forces one or if we have wizards cached
force_refresh = util.flask.cache_check_headers() or "_refresh" in request.values or wizard_active(_templates.get(locale))
# we force a refresh if '_refresh' is in the query or if we have wizards cached
force_refresh = "_refresh" in request.values or wizard_active(_templates.get(locale))
# if we need to refresh our template cache or it's not yet set, process it
fetch_template_data(refresh=force_refresh)