From 3b1874ea25f1d44ea33e7249b0a300d4880839de Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Thu, 21 Nov 2019 08:48:44 -0600 Subject: [PATCH] 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. --- AUTHORS.md | 1 + src/octoprint/plugin/types.py | 9 ++++----- src/octoprint/server/views.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 8398e0cb5..297e47fdb 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -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 diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index d625844ec..0bc9dd113 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -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`` diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 181869654..9b8bbe756 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -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)