Skip to content

www/nginx: Add basic support for forced caching #4481

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

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

ltning
Copy link
Contributor

@ltning ltning commented Jan 18, 2025

Fixes #4475 by adding an optional, advanced field for locations, which uses the simples variant of the proxy_cache_valid statement. By default, this will set the given cache validity for results with HTTP 200, 301 or 302 response codes.

Making sure caching only happens for objects that should be cached remains an exercise for the user. This helps the cases where upstreams don't set cache headers at all, in which case nginx will not cache.

@kulikov-a
Copy link
Member

Hi!
Maybe it would be more correct to do it the way cache paths (or, for example, resolvers) are made? Separately defined parameters (with a full set of attributes) with the ability to reuse?

@ltning
Copy link
Contributor Author

ltning commented Jan 19, 2025

Perhaps - but in this case it might be letting "perfect" get in the way of "good"; the more advanced approach would take a lot more work, and testing. At least until that is done, this is likely to solve a lot of the situations where it might be a problem.
Happy to help test if someone makes a more feature-complete implementation, but I would much appreciate if this was merged in the meantime, assuming it does what it does correctly :)

Comment on lines +352 to +354
<cache_valid type="IntegerField">
<Required>N</Required>
</cache_valid>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<cache_valid type="IntegerField">
<Required>N</Required>
</cache_valid>
<cache_valid type="IntegerField"/>

Copy link
Member

@fichtner fichtner left a comment

Choose a reason for hiding this comment

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

ok for me as advanced opt-in

@fichtner fichtner self-assigned this Jan 20, 2025
@kulikov-a
Copy link
Member

@fichtner @ltning if you give me a couple of weeks i will try to find time and add this to https://github.com/kulikov-a/plugins/tree/nginx_1.35 and make a pr

@fichtner
Copy link
Member

@kulikov-a 25.1 is due next week and I don't mind having both a simple short term and a better long term solution

@kulikov-a
Copy link
Member

got it, thanks!)

@fichtner fichtner merged commit dc225a5 into opnsense:master Jan 20, 2025
@fichtner
Copy link
Member

@kulikov-a thanks, looking forward to your proposal :)

@ltning merged, thanks!

kulikov-a added a commit to kulikov-a/plugins that referenced this pull request Mar 16, 2025
proxy_intercept_errors support (opnsense#4224)
multiple client auth CA support (opnsense#4421)
HTTP/2 server checkbox (opnsense#4272)
sendfile form typo (opnsense#4436)
variables  hashes (opnsense#4360)
proxy_cache_valid (opnsense#4481)
@kulikov-a kulikov-a mentioned this pull request Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

nginx: add proxy_cache_valid setting to make caching work
3 participants