Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rest] Add no-cache directive to cached REST responses #3970

Merged
merged 1 commit into from
Dec 27, 2023

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Dec 27, 2023

Fixes openhab/openhab-webui#2102, where Firefox users reported problems with outdated data in Main UI due to Firefox handling caching different than Chromium.
Also reported on the community, e.g. https://community.openhab.org/t/firefox-oh-4-0-1-issues/148633 and https://community.openhab.org/t/updating-widget-code-not-working/148265.

This forces the browser to revalidate the cache every time it is accessed to ensure the data is always fresh. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#directives.

This is approach is also suggested in the mdn web docs, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#up-to-date_contents_always.

This PR should be backported to 4.1.x.

Fixes openhab/openhab-webui#2102.

This forces the browser to revalidate the cache every time it is accessed to ensure the data is always fresh.
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#directives.

This is approach is also suggested in the mdn web docs, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#up-to-date_contents_always.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 requested a review from a team as a code owner December 27, 2023 16:20
@wborn
Copy link
Member

wborn commented Dec 27, 2023

Do you know why the CacheControl is used in these Resources and not others like InboxResource or AddonResource?

@florian-h05
Copy link
Contributor Author

florian-h05 commented Dec 27, 2023

At the moment, only some of the resources have implemented caching, so obviously only the Resources with caching implement need CacheControl.

Would be nice to extend caching, but at the moment we already have covered the most important endpoints used in the UI, and I expect the already existing caching to have much higher effect than for the missing caching.

Copy link
Member

@wborn wborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It makes sense to only cache the most frequently used and biggest responses.

@wborn wborn added the bug An unexpected problem or unintended behavior of the Core label Dec 27, 2023
@wborn wborn merged commit f5bd7f9 into openhab:main Dec 27, 2023
3 checks passed
@wborn wborn added this to the 4.2 milestone Dec 27, 2023
wborn pushed a commit that referenced this pull request Dec 27, 2023
Fixes openhab/openhab-webui#2102.

This forces the browser to revalidate the cache every time it is accessed to ensure the data is always fresh.
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#directives.

This is approach is also suggested in the mdn web docs, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#up-to-date_contents_always.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@wborn wborn added the patch A PR that has been cherry-picked to a patch release branch label Dec 27, 2023
@florian-h05 florian-h05 deleted the rest-cachecontrol-nocache branch December 27, 2023 17:37
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/oh4-4-1-gui-doesnt-show-installed-bindings/152413/37

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/item-not-on-panel/153086/3

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/debian-package-4-1-1-not-displaying-web-interface-correctly-almost-unuseable/153454/14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core patch A PR that has been cherry-picked to a patch release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[openhab-4] Equipment not visible after adding in the semantic model
3 participants