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 caching for add-on resource #4107

Merged
merged 8 commits into from Mar 27, 2024

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Feb 23, 2024

As there are no registry listeners to use, I decided to listen to AddonEvents.

/cc @jimtng

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 requested a review from a team as a code owner February 23, 2024 09:16
Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

Are you sure this works the way you expect it to do? Server-side changes to remote add-on services (e.g. a new add-on post in the forum) do not produce an AddonEvent and will never be picked up until a system restart.

@florian-h05
Copy link
Contributor Author

No, I’m not sure.

Do you know a better way to detect changes?

@J-N-K
Copy link
Member

J-N-K commented Mar 10, 2024

The remote add-on services cache their content, too. The refresh time is 15 min, so I guess an automatic expiry of the cache with half of that would probably mitigate the issue.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05
Copy link
Contributor Author

Thanks for the idea, I have just pushed that!

FYI I switched from having a CACHE_CONTROL constant on RESTConstants to having a default cache control getter on the RESTConstant class to migitate to risk that somewhere the const could be modified which would then apply to all places where the const is used.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05
Copy link
Contributor Author

@J-N-K Can you please have a look at this PR?

Comment on lines 43 to 50

public static CacheControl cacheControl() {
CacheControl cc = new CacheControl();
cc.setNoCache(true);
cc.setMustRevalidate(true);
cc.setPrivate(true);
return cc;
}
Copy link
Member

Choose a reason for hiding this comment

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

I think haveing a static final CACHE_CONTROL constant would be better than creating a new object every time. I also feel that the danger these setting might be modified is very low.

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

@florian-h05 florian-h05 requested a review from J-N-K March 24, 2024 20:23
@florian-h05
Copy link
Contributor Author

@J-N-K Done 👍

Sign-Off is missing for the revert commit, hope that's okay. Otherwise I need to force push ...

@J-N-K J-N-K added bug An unexpected problem or unintended behavior of the Core REST/SSE labels Mar 27, 2024
@J-N-K J-N-K added this to the 4.2 milestone Mar 27, 2024
@J-N-K J-N-K added enhancement An enhancement or new feature of the Core and removed bug An unexpected problem or unintended behavior of the Core labels Mar 27, 2024
@J-N-K J-N-K merged commit 7f47d82 into openhab:main Mar 27, 2024
3 checks passed
@florian-h05 florian-h05 deleted the rest-caching-addons branch March 27, 2024 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core REST/SSE
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants