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

Consider conditional view caching #22391

Closed
fred84 opened this issue Feb 8, 2019 · 1 comment
Closed

Consider conditional view caching #22391

fred84 opened this issue Feb 8, 2019 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@fred84
Copy link
Contributor

fred84 commented Feb 8, 2019

Currently we are only able to set size for views cache in subclasses of AbstractCachingViewResolver. When cache size limit is reached, oldest entry is evicted.

In my project I have following access pattern:

  1. several html views which are accessed frequently
  2. many RedirectView, which differs only in path segment (/returnfromsomewhere/SOMEIDENTIFIER) and are accessed only once. I don't want them to stay in cache.

I added simple view name filter to check if viewName should be cached.

Configuration example:

    @Configuration
    static class ViewResolverConfiguration {

        @Autowired
        private List<ViewResolver> viewResolvers;

        @PostConstruct
        public void configure() {
            viewResolvers.forEach(v -> {
                if (v instanceof AbstractCachingViewResolver) {
                    ((AbstractCachingViewResolver) v).setCacheFilter(n -> !n.startsWith("redirect"));
                }
            });
        }
    }

Is it worth creating PR?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 8, 2019
@poutsma
Copy link
Contributor

poutsma commented Feb 18, 2019

Is it worth creating PR?

Yes, I think it would be useful for AbstractCachingViewResolver to be able to express cacheability of views. At first glance, it should probably be inserted here.

The filter should operate on more than just the name, though. It should provide all available variables for the filter to make its decision. Looking at the line linked to above, Locale and View are also available, so these should be passed to the filter as well (i.e. it should be possible for a filter to decide on cacheability depending on the View instance itself or its locale, not just its name.)

@sbrannen sbrannen added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Mar 17, 2019
@poutsma poutsma self-assigned this Jul 29, 2019
@poutsma poutsma removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 29, 2019
@poutsma poutsma added this to the 5.2 RC1 milestone Jul 29, 2019
@poutsma poutsma closed this as completed in 59aee92 Aug 1, 2019
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

No branches or pull requests

4 participants