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

Introduce caching for functional routing #29985

Closed
wants to merge 1 commit into from

Conversation

JakobFels
Copy link

Currently the functional API does not support any kind of caching for resources. I was trying to replicate an nginx setup with multiple virtual hosts, each having their own assets folder.

So my code would contain something like:

route.nest(
  RequestPredicates.headers(headers -> "www.exmple.com".equals(headers.host().getHostString())),
  builder -> builder
    .add(ResourcesHandler.resources("/**", getHostSpecificResourceDir())

With this setup, I saw no option to define any kind of caching for these resources, because ResourceHandlerFunction was returning an EntityResponse which could not be modified.

This PR introduces caching support for the .resources instruction. Implementing the ResourceCacheLookupStrategy interface allows for either defining a general caching rule (e.g. max-age=60 for all resources), or to define custom cache behaviour per file (e.g. max-age=3600 if resource is an xml file).

The default behaviour, if no strategy is provided, is to not cache at all, preserving the status quo.

I have signed the CLA

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 16, 2023
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Feb 16, 2023
@JakobFels
Copy link
Author

Just wanted to know if anything is missing to get this moving

@poutsma poutsma self-assigned this Oct 3, 2023
@poutsma poutsma removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 3, 2023
@poutsma poutsma added this to the 6.1.0-RC1 milestone Oct 3, 2023
@poutsma poutsma closed this in ad50de1 Oct 10, 2023
poutsma added a commit that referenced this pull request Oct 10, 2023
@poutsma
Copy link
Contributor

poutsma commented Oct 10, 2023

Thank you for submitting a PR.

I decided to take an alternative approach (see 307a2c7) that allows you to change any headers for server resources, not just Cache-Control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants