All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.cache.http.HttpCacheableReactiveAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.cache.http;


import java.util.Set;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping;
import org.zodiac.autoconfigure.cache.condition.ConditionalOnHttpCacheEnabled;
import org.zodiac.cache.http.reactive.HttpCacheableWebFilter;
import org.zodiac.commons.util.Colls;

@SpringBootConfiguration
@ConditionalOnHttpCacheEnabled
@ConditionalOnWebApplication(type = Type.REACTIVE)
@AutoConfigureAfter(value = {HttpCacheableAutoConfiguration.class})
@ConditionalOnClass(value = {org.zodiac.cache.http.HttpCacheable.class})
@ConditionalOnBean(value = {org.springframework.cache.CacheManager.class})
public class HttpCacheableReactiveAutoConfiguration implements WebFluxConfigurer {

    private final WebFluxProperties webFluxProperties;
    private final HttpCacheableProperties httpCacheProperties;
    private final org.zodiac.cache.http.HttpCacheService httpCacheService;

    public HttpCacheableReactiveAutoConfiguration(WebFluxProperties webFluxProperties, HttpCacheableProperties httpCacheProperties,
        org.zodiac.cache.http.HttpCacheService httpCacheService) {
        this.webFluxProperties = webFluxProperties;
        this.httpCacheProperties = httpCacheProperties;
        this.httpCacheService = httpCacheService;
    }

    @Bean
    @ConditionalOnMissingBean
    protected HttpCacheableWebFilter httpCacheableWebFilter(RequestMappingHandlerMapping requestMappingHandlerMapping) {
        Set excludePatterns = Colls.set(httpCacheProperties.getExcludePatterns());
        String staticPathPattern = webFluxProperties.getStaticPathPattern();
        /* 如果静态 目录 不为“/**” */
        if (!HttpCacheableProperties.DEFAULT_STATIC_PATH_PATTERN.equals(staticPathPattern.trim())) {
            excludePatterns.add(staticPathPattern);
        }
        return new HttpCacheableWebFilter(httpCacheProperties, httpCacheService, requestMappingHandlerMapping);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy