Skip to content

Consider conditional view caching #22391

@fred84

Description

@fred84

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?

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions