org.springframework.http.CacheControl.maxAge()

Here are the examples of the java api org.springframework.http.CacheControl.maxAge() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

63 Examples 7

19 View Source File : FirebaseConfigController.java
License : Apache License 2.0
Project Creator : zhcet-amu

@Cacheable("firebase-messaging-sw")
@GetMapping("/firebase-messaging-sw.js")
public ResponseEnreplacedy<String> firebaseMessagingSw() {
    String rendered = templateEngine.process("js/firebase-messaging-sw", getFirebaseContext());
    return ResponseEnreplacedy.ok().contentType(MediaType.parseMediaType("text/javascript")).cacheControl(CacheControl.maxAge(1, TimeUnit.DAYS).sMaxAge(1, TimeUnit.DAYS)).body(rendered);
}

19 View Source File : FirebaseConfigController.java
License : Apache License 2.0
Project Creator : zhcet-amu

@Cacheable("firebase-config")
@GetMapping("/js/firebase-config.js")
public ResponseEnreplacedy<String> firebaseConfig() {
    String rendered = templateEngine.process("js/firebase-config", getFirebaseContext());
    return ResponseEnreplacedy.ok().contentType(MediaType.parseMediaType("text/javascript")).cacheControl(CacheControl.maxAge(365, TimeUnit.DAYS).sMaxAge(365, TimeUnit.DAYS).cachePublic()).body(rendered);
}

19 View Source File : ServiceWorkerController.java
License : Apache License 2.0
Project Creator : zhcet-amu

@Cacheable("sw")
@GetMapping("/sw.js")
public ResponseEnreplacedy<String> serviceWorker() {
    ClreplacedPathResource clreplacedPathResource = new ClreplacedPathResource("src/sw.mjs");
    String loaded = null;
    try {
        loaded = IOUtils.toString(clreplacedPathResource.getInputStream(), "UTF-8");
    } catch (IOException e) {
        log.error("Error loading service worker", e);
    }
    return ResponseEnreplacedy.ok().contentType(MediaType.parseMediaType("text/javascript")).cacheControl(CacheControl.maxAge(0, TimeUnit.SECONDS)).body(loaded);
}

19 View Source File : MvcNamespaceTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void testResourcesWithResolversTransformersCustom() throws Exception {
    loadBeanDefinitions("mvc-config-resources-chain-no-auto.xml");
    SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.clreplaced);
    replacedertNotNull(mapping);
    replacedertNotNull(mapping.getUrlMap().get("/resources/**"));
    ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"), ResourceHttpRequestHandler.clreplaced);
    replacedertNotNull(handler);
    replacedertThat(handler.getCacheControl().getHeaderValue(), Matchers.equalTo(CacheControl.maxAge(1, TimeUnit.HOURS).sMaxAge(30, TimeUnit.MINUTES).cachePublic().getHeaderValue()));
    List<ResourceResolver> resolvers = handler.getResourceResolvers();
    replacedertThat(resolvers, Matchers.hreplacedize(3));
    replacedertThat(resolvers.get(0), Matchers.instanceOf(VersionResourceResolver.clreplaced));
    replacedertThat(resolvers.get(1), Matchers.instanceOf(EncodedResourceResolver.clreplaced));
    replacedertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.clreplaced));
    VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(0);
    replacedertThat(versionResolver.getStrategyMap().get("/**/*.js"), Matchers.instanceOf(FixedVersionStrategy.clreplaced));
    replacedertThat(versionResolver.getStrategyMap().get("/**"), Matchers.instanceOf(ContentVersionStrategy.clreplaced));
    List<ResourceTransformer> transformers = handler.getResourceTransformers();
    replacedertThat(transformers, Matchers.hreplacedize(2));
    replacedertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.clreplaced));
    replacedertThat(transformers.get(1), Matchers.instanceOf(AppCacheManifestTransformer.clreplaced));
}

19 View Source File : StaticResourcesWebConfiguration.java
License : MIT License
Project Creator : tillias

protected CacheControl getCacheControl() {
    return CacheControl.maxAge(getJHipsterHttpCacheProperty(), TimeUnit.DAYS).cachePublic();
}

19 View Source File : ZipkinQueryApiV2.java
License : Apache License 2.0
Project Creator : Tanzu-Solutions-Engineering

/**
 * We cache names if there are more than 3 services. This helps people getting started: if we
 * cache empty results, users have more questions. We replacedume caching becomes a concern when zipkin
 * is in active use, and active use usually implies more than 3 services.
 */
ResponseEnreplacedy<List<String>> maybeCacheNames(List<String> names) {
    ResponseEnreplacedy.BodyBuilder response = ResponseEnreplacedy.ok();
    if (serviceCount > 3) {
        response.cacheControl(CacheControl.maxAge(namesMaxAge, TimeUnit.SECONDS).mustRevalidate());
    }
    return response.body(names);
}

19 View Source File : StaticResourcesConfig.java
License : GNU Affero General Public License v3.0
Project Creator : retro-game

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/static/**").addResourceLocations("clreplacedpath:/public/static/").setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS));
}

19 View Source File : EnableWebMvcConfiguration.java
License : Apache License 2.0
Project Creator : LinkedBear

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/js/**").addResourceLocations("/js/").setCacheControl(CacheControl.maxAge(Duration.ofDays(30)));
}

19 View Source File : MvcNamespaceTests.java
License : Apache License 2.0
Project Creator : langtianya

@Test
public void testResourcesWithResolversTransformersCustom() throws Exception {
    loadBeanDefinitions("mvc-config-resources-chain-no-auto.xml", 12);
    SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.clreplaced);
    replacedertNotNull(mapping);
    replacedertNotNull(mapping.getUrlMap().get("/resources/**"));
    ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"), ResourceHttpRequestHandler.clreplaced);
    replacedertNotNull(handler);
    replacedertThat(handler.getCacheControl().getHeaderValue(), Matchers.equalTo(CacheControl.maxAge(1, TimeUnit.HOURS).sMaxAge(30, TimeUnit.MINUTES).cachePublic().getHeaderValue()));
    List<ResourceResolver> resolvers = handler.getResourceResolvers();
    replacedertThat(resolvers, Matchers.hreplacedize(3));
    replacedertThat(resolvers.get(0), Matchers.instanceOf(VersionResourceResolver.clreplaced));
    replacedertThat(resolvers.get(1), Matchers.instanceOf(GzipResourceResolver.clreplaced));
    replacedertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.clreplaced));
    VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(0);
    replacedertThat(versionResolver.getStrategyMap().get("/**/*.js"), Matchers.instanceOf(FixedVersionStrategy.clreplaced));
    replacedertThat(versionResolver.getStrategyMap().get("/**"), Matchers.instanceOf(ContentVersionStrategy.clreplaced));
    List<ResourceTransformer> transformers = handler.getResourceTransformers();
    replacedertThat(transformers, Matchers.hreplacedize(2));
    replacedertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.clreplaced));
    replacedertThat(transformers.get(1), Matchers.instanceOf(AppCacheManifestTransformer.clreplaced));
}

19 View Source File : PlayerRestController.java
License : GNU General Public License v3.0
Project Creator : ingresspub

@GetMapping("/r/player/portals/upc.iitc.json")
public ResponseEnreplacedy<List<Circle>> listUpcForIitc(@RequestParam(value = "color", required = false, defaultValue = "#ff00ff") String color, @RequestParam(value = "radius", required = false, defaultValue = "20") int radius) {
    return ResponseEnreplacedy.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.DAYS)).body(playerService.listUpc().stream().map(coordinate -> new Circle(coordinate, color, radius)).collect(Collectors.toList()));
}

19 View Source File : PlayerRestController.java
License : GNU General Public License v3.0
Project Creator : ingresspub

@GetMapping("/r/player/profile/events/level_up.json")
public ResponseEnreplacedy<CacheableData<List<Event>>> listLevelUpEvents() {
    return ResponseEnreplacedy.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.DAYS)).body(new CacheableData<>(playerService.listLevelUpEvents(), Clock.systemUTC().millis()));
}

19 View Source File : PlayerRestController.java
License : GNU General Public License v3.0
Project Creator : ingresspub

@GetMapping("/r/player/portals/upv.json")
public ResponseEnreplacedy<CacheableData<List<Coordinate>>> listUpv(@RequestParam(value = "excludeCaptured", required = false, defaultValue = "false") boolean excludeCaptured) {
    return ResponseEnreplacedy.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.DAYS)).body(new CacheableData<>(playerService.listUpv(excludeCaptured), Clock.systemUTC().millis()));
}

19 View Source File : WebConfigConfigurer.java
License : GNU Affero General Public License v3.0
Project Creator : Hello-hao

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    Print.Normal("修改响应头开始");
    registry.addResourceHandler("/**").addResourceLocations("clreplacedpath:/static/").setCacheControl(CacheControl.maxAge(1, TimeUnit.SECONDS).cachePublic());
}

18 View Source File : StaticResourcesWebConfigurerTest.java
License : MIT License
Project Creator : tillias

@Test
public void shoudCreateCacheControlWithSpecificConfigurationInProperties() {
    props.getHttp().getCache().setTimeToLiveInDays(MAX_AGE_TEST);
    CacheControl cacheExpected = CacheControl.maxAge(MAX_AGE_TEST, TimeUnit.DAYS).cachePublic();
    replacedertThat(staticResourcesWebConfiguration.getCacheControl()).extracting(CacheControl::getHeaderValue).isEqualTo(cacheExpected.getHeaderValue());
}

18 View Source File : StaticResourcesWebConfigurerTest.java
License : MIT License
Project Creator : tillias

@Test
public void shouldInitializeResourceHandlerWithCacheControlAndLocations() {
    CacheControl ccExpected = CacheControl.maxAge(5, TimeUnit.DAYS).cachePublic();
    when(staticResourcesWebConfiguration.getCacheControl()).thenReturn(ccExpected);
    ResourceHandlerRegistration resourceHandlerRegistration = spy(new ResourceHandlerRegistration(RESOURCE_PATHS));
    staticResourcesWebConfiguration.initializeResourceHandler(resourceHandlerRegistration);
    verify(staticResourcesWebConfiguration, times(1)).getCacheControl();
    verify(resourceHandlerRegistration, times(1)).setCacheControl(ccExpected);
    verify(resourceHandlerRegistration, times(1)).addResourceLocations(RESOURCE_LOCATIONS);
}

18 View Source File : StaticResourcesWebConfigurerTest.java
License : MIT License
Project Creator : tillias

@Test
public void shoudCreateCacheControlBasedOnJhipsterDefaultProperties() {
    CacheControl cacheExpected = CacheControl.maxAge(JHipsterDefaults.Http.Cache.timeToLiveInDays, TimeUnit.DAYS).cachePublic();
    replacedertThat(staticResourcesWebConfiguration.getCacheControl()).extracting(CacheControl::getHeaderValue).isEqualTo(cacheExpected.getHeaderValue());
}

18 View Source File : ResourceConfig.java
License : MIT License
Project Creator : ralscha

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/", "/index.html").addResourceLocations("clreplacedpath:/static/").setCacheControl(CacheControl.noCache()).resourceChain(false).addResolver(new EncodedResourceResolver());
    registry.addResourceHandler("/**").addResourceLocations("clreplacedpath:/static/").setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS).cachePublic()).resourceChain(false).addResolver(new EncodedResourceResolver());
}

18 View Source File : TextsController.java
License : Mozilla Public License 2.0
Project Creator : RadarCOVID

@Loggable
@GetMapping(produces = "application/json")
@Operation(summary = "Get texts by locale and CCAA", description = "Get texts by locale and CCAA", tags = { "texts" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "successful operation", content = @Content(schema = @Schema(implementation = TextCustomMap.clreplaced))), @ApiResponse(responseCode = "400", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "404", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "500", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))) })
public ResponseEnreplacedy<TextCustomMap> getTexts(@RequestParam(value = "ccaa", required = false, defaultValue = DEFAULT_CCAA) final String ccaa, @RequestParam(value = "locale", required = false, defaultValue = DEFAULT_LOCALE) final String locale, @RequestParam(value = "platform", required = false) final String platform, @RequestParam(value = "version", required = false) final String version) {
    return ResponseEnreplacedy.status(HttpStatus.OK).cacheControl(CacheControl.maxAge(cacheTexts, TimeUnit.HOURS)).body(this.service.getTexts(ccaa, locale, platform, version));
}

18 View Source File : WebMvcConfig.java
License : Apache License 2.0
Project Creator : PaaS-TA

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    registry.addResourceHandler("/resources/css/fonts/**").addResourceLocations("/resources/css/fonts/").setCacheControl(CacheControl.maxAge(86400, TimeUnit.SECONDS));
}

18 View Source File : ImageResource.java
License : Apache License 2.0
Project Creator : otto-de

/**
 * GET  /images/:id : get the "id" image.
 *
 * @param id the id of the imageDTO to retrieve
 * @return the ResponseEnreplacedy with status 200 (OK) and with body the imageDTO, or with status 404 (Not Found)
 */
@GetMapping("/images/{id}/content")
public ResponseEnreplacedy<byte[]> getImageContent(@PathVariable Long id, @RequestParam(value = "size", required = false) String size) {
    log.debug("REST request to get Image : {}", id);
    Optional<ImageDTO> imageDTO = imageService.findOne(id);
    if (!imageDTO.isPresent()) {
        return new ResponseEnreplacedy<>(HttpStatus.NOT_FOUND);
    }
    ImageDTO image = imageDTO.get();
    size = size == null ? "LARGE" : size.toUpperCase();
    byte[] imageBlob;
    String contentType;
    if (size.equals("SMALL")) {
        imageBlob = image.getSmall();
        contentType = image.getSmallContentType();
    } else if (size.equals("MEDIUM")) {
        imageBlob = image.getMedium();
        contentType = image.getMediumContentType();
    } else {
        imageBlob = image.getLarge();
        contentType = image.getLargeContentType();
    }
    return ResponseEnreplacedy.ok().header("Content-Type", contentType).cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)).body(imageBlob);
}

18 View Source File : Config.java
License : GNU General Public License v3.0
Project Creator : nurkiewicz

private Mono<ServerResponse> routerCached(ServerRequest request) {
    Map<String, String> book = new HashMap<>();
    book.put("replacedle", "Tytuł");
    String version = String.valueOf(book.hashCode());
    return ServerResponse.ok().contentType(APPLICATION_JSON).cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)).eTag(// lastModified is also available
    version).syncBody(book);
}

18 View Source File : StaticResourcesWebConfigurerTest.java
License : Apache License 2.0
Project Creator : jhipster

@Test
void shouldInitializeResourceHandlerWithCacheControlAndLocations() {
    CacheControl ccExpected = CacheControl.maxAge(5, TimeUnit.DAYS).cachePublic();
    when(staticResourcesWebConfiguration.getCacheControl()).thenReturn(ccExpected);
    ResourceHandlerRegistration resourceHandlerRegistration = spy(new ResourceHandlerRegistration(RESOURCE_PATHS));
    staticResourcesWebConfiguration.initializeResourceHandler(resourceHandlerRegistration);
    verify(staticResourcesWebConfiguration, times(1)).getCacheControl();
    verify(resourceHandlerRegistration, times(1)).setCacheControl(ccExpected);
    verify(resourceHandlerRegistration, times(1)).addResourceLocations(RESOURCE_LOCATIONS);
}

18 View Source File : StaticResourcesWebConfigurerTest.java
License : Apache License 2.0
Project Creator : jhipster

@Test
void shoudCreateCacheControlWithSpecificConfigurationInProperties() {
    props.getHttp().getCache().setTimeToLiveInDays(MAX_AGE_TEST);
    CacheControl cacheExpected = CacheControl.maxAge(MAX_AGE_TEST, TimeUnit.DAYS).cachePublic();
    replacedertThat(staticResourcesWebConfiguration.getCacheControl()).extracting(CacheControl::getHeaderValue).isEqualTo(cacheExpected.getHeaderValue());
}

18 View Source File : StaticResourcesWebConfigurerTest.java
License : Apache License 2.0
Project Creator : jhipster

@Test
void shoudCreateCacheControlBasedOnJhipsterDefaultProperties() {
    CacheControl cacheExpected = CacheControl.maxAge(JHipsterDefaults.Http.Cache.timeToLiveInDays, TimeUnit.DAYS).cachePublic();
    replacedertThat(staticResourcesWebConfiguration.getCacheControl()).extracting(CacheControl::getHeaderValue).isEqualTo(cacheExpected.getHeaderValue());
}

18 View Source File : PlayerRestController.java
License : GNU General Public License v3.0
Project Creator : ingresspub

@GetMapping("/r/player/portals/upv.iitc.json")
public ResponseEnreplacedy<List<Circle>> listUpvForIitc(@RequestParam(value = "excludeCaptured", required = false, defaultValue = "false") boolean excludeCaptured, @RequestParam(value = "color", required = false, defaultValue = "#ff00ff") String color, @RequestParam(value = "radius", required = false, defaultValue = "20") int radius) {
    return ResponseEnreplacedy.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.DAYS)).body(playerService.listUpv(excludeCaptured).stream().map(coordinate -> new Circle(coordinate, color, radius)).collect(Collectors.toList()));
}

18 View Source File : PlayerRestController.java
License : GNU General Public License v3.0
Project Creator : ingresspub

@GetMapping("/r/player/portals/upc.json")
public ResponseEnreplacedy<CacheableData<List<Coordinate>>> listUpc() {
    return ResponseEnreplacedy.ok().cacheControl(CacheControl.maxAge(1, TimeUnit.DAYS)).body(new CacheableData<>(playerService.listUpc(), Clock.systemUTC().millis()));
}

18 View Source File : CacheInterceptor.java
License : BSD 3-Clause "New" or "Revised" License
Project Creator : dhis2

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpServletResponse response = ServletActionContext.getResponse();
    if (HttpMethod.GET == HttpMethod.resolve(request.getMethod())) {
        response.setHeader("Cache-Control", CacheControl.maxAge(seconds, TimeUnit.SECONDS).cachePublic().getHeaderValue());
    }
    return invocation.invoke();
}

18 View Source File : BootstrapController.java
License : Apache License 2.0
Project Creator : ATLANTBH

/**
 * Gets bootstrap.
 *
 * @return the bootstrap
 */
@RequestMapping(method = RequestMethod.GET)
public ResponseEnreplacedy<Bootstrap> getBootstrap() {
    return ResponseEnreplacedy.ok().cacheControl(CacheControl.maxAge(2, TimeUnit.HOURS)).body(bootstrap);
}

17 View Source File : ResourceWebHandlerTests.java
License : Apache License 2.0
Project Creator : SourceHot

@BeforeEach
public void setup() throws Exception {
    List<Resource> locations = new ArrayList<>(2);
    locations.add(new ClreplacedPathResource("test/", getClreplaced()));
    locations.add(new ClreplacedPathResource("testalternatepath/", getClreplaced()));
    locations.add(new ClreplacedPathResource("META-INF/resources/webjars/"));
    this.handler = new ResourceWebHandler();
    this.handler.setLocations(locations);
    this.handler.setCacheControl(CacheControl.maxAge(3600, TimeUnit.SECONDS));
    this.handler.afterPropertiesSet();
}

17 View Source File : MasterDataController.java
License : Mozilla Public License 2.0
Project Creator : RadarCOVID

@Loggable
@GetMapping(path = { "/ccaa" }, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get availables autonomous communities", description = "Get availables autonomous communities", tags = { "masterData" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "successful operation", content = @Content(array = @ArraySchema(schema = @Schema(implementation = CcaaKeyValueDto.clreplaced)))), @ApiResponse(responseCode = "400", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "404", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "500", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))) })
public ResponseEnreplacedy<List<CcaaKeyValueDto>> getCcaa(@RequestParam(value = "locale", required = false, defaultValue = DEFAULT_LOCALE) final String locale, @RequestParam(value = "platform", required = false) final String platform, @RequestParam(value = "version", required = false) final String version, @RequestParam(value = "additionalInfo", required = false, defaultValue = "false") final boolean additionalInfo) {
    return ResponseEnreplacedy.status(HttpStatus.OK).cacheControl(CacheControl.maxAge(cacheCCAA, TimeUnit.HOURS)).body(this.service.getAutonomousCommunities(locale, platform, version, additionalInfo));
}

17 View Source File : JweWellKnownJwksController.java
License : MIT License
Project Creator : Onegini

@GetMapping(JWKS_KEYS_PATH)
public ResponseEnreplacedy<JSONObject> getJwks() {
    final JWEAlgorithm chosenAlgorithm = ASYMMETRIC_ENCRYPTION_ALGORITHM;
    validateAlgorithmSupport(chosenAlgorithm);
    jwkSetProvider.getPublicJWKS(chosenAlgorithm);
    return ResponseEnreplacedy.status(SC_OK).cacheControl(CacheControl.maxAge(MAX_AGE, SECONDS)).body(jwkSetProvider.getPublicJWKS(chosenAlgorithm));
}

17 View Source File : ReactorController.java
License : GNU General Public License v3.0
Project Creator : nurkiewicz

@GetMapping(value = "/cached")
Mono<ResponseEnreplacedy<Map<String, String>>> cached() {
    return Mono.fromCallable(() -> {
        Map<String, String> book = new HashMap<>();
        book.put("replacedle", "Lord Of The Rings");
        return book;
    }).map(book -> ResponseEnreplacedy.ok().contentType(APPLICATION_JSON).cacheControl(CacheControl.maxAge(30, TimeUnit.DAYS)).eTag(String.valueOf(book.hashCode())).body(book));
}

17 View Source File : AppMVCConfiguration.java
License : Apache License 2.0
Project Creator : epam

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler(CACHED_RESOURCES_PATH).addResourceLocations(CACHED_RESOURCES_LOCATION).setCacheControl(CacheControl.maxAge(staticResourcesCachePeriod, TimeUnit.SECONDS).cachePublic().mustRevalidate()).resourceChain(true);
}

16 View Source File : WebMvcAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void replacedertCachePeriod(replacedertableWebApplicationContext context) {
    Map<String, Object> handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.clreplaced));
    replacedertThat(handlerMap).hreplacedize(2);
    for (Object handler : handlerMap.keySet()) {
        if (handler instanceof ResourceHttpRequestHandler) {
            replacedertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(-1);
            replacedertThat(((ResourceHttpRequestHandler) handler).getCacheControl()).isEqualToComparingFieldByField(CacheControl.maxAge(5, TimeUnit.SECONDS));
        }
    }
}

16 View Source File : WebMvcAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

private void replacedertCacheControl(replacedertableWebApplicationContext context) {
    Map<String, Object> handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.clreplaced));
    replacedertThat(handlerMap).hreplacedize(2);
    for (Object handler : handlerMap.keySet()) {
        if (handler instanceof ResourceHttpRequestHandler) {
            replacedertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(-1);
            replacedertThat(((ResourceHttpRequestHandler) handler).getCacheControl()).isEqualToComparingFieldByField(CacheControl.maxAge(5, TimeUnit.SECONDS).proxyRevalidate());
        }
    }
}

16 View Source File : WebFluxAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void cacheControl() {
    this.contextRunner.withPropertyValues("spring.resources.cache.cachecontrol.max-age:5", "spring.resources.cache.cachecontrol.proxy-revalidate:true").run((context) -> {
        Map<PathPattern, Object> handlerMap = getHandlerMap(context);
        replacedertThat(handlerMap).hreplacedize(2);
        for (Object handler : handlerMap.values()) {
            if (handler instanceof ResourceWebHandler) {
                replacedertThat(((ResourceWebHandler) handler).getCacheControl()).isEqualToComparingFieldByField(CacheControl.maxAge(5, TimeUnit.SECONDS).proxyRevalidate());
            }
        }
    });
}

16 View Source File : WebFluxAutoConfigurationTests.java
License : Apache License 2.0
Project Creator : yuanmabiji

@Test
public void cachePeriod() {
    this.contextRunner.withPropertyValues("spring.resources.cache.period:5").run((context) -> {
        Map<PathPattern, Object> handlerMap = getHandlerMap(context);
        replacedertThat(handlerMap).hreplacedize(2);
        for (Object handler : handlerMap.values()) {
            if (handler instanceof ResourceWebHandler) {
                replacedertThat(((ResourceWebHandler) handler).getCacheControl()).isEqualToComparingFieldByField(CacheControl.maxAge(5, TimeUnit.SECONDS));
            }
        }
    });
}

16 View Source File : ResourceWebHandlerTests.java
License : MIT License
Project Creator : Vip-Augus

@Before
public void setup() throws Exception {
    List<Resource> locations = new ArrayList<>(2);
    locations.add(new ClreplacedPathResource("test/", getClreplaced()));
    locations.add(new ClreplacedPathResource("testalternatepath/", getClreplaced()));
    locations.add(new ClreplacedPathResource("META-INF/resources/webjars/"));
    this.handler = new ResourceWebHandler();
    this.handler.setLocations(locations);
    this.handler.setCacheControl(CacheControl.maxAge(3600, TimeUnit.SECONDS));
    this.handler.afterPropertiesSet();
}

16 View Source File : FirebaseJwtTokenDecoderTests.java
License : Apache License 2.0
Project Creator : GoogleCloudPlatform

private RestOperations mockRestOperations(Map<String, String> payload) {
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CACHE_CONTROL, CacheControl.maxAge(3600L, TimeUnit.SECONDS).getHeaderValue());
    ResponseEnreplacedy<Map<String, String>> response = new ResponseEnreplacedy<>(payload, headers, HttpStatus.OK);
    return mockRestOperations(response);
}

16 View Source File : SearchController.java
License : Apache License 2.0
Project Creator : Erudika

@ResponseBody
@GetMapping("/feed.xml")
public ResponseEnreplacedy<String> feed() {
    String feed = "";
    try {
        feed = new SyndFeedOutput().outputString(getFeed());
    } catch (Exception ex) {
        logger.error("Could not generate feed", ex);
    }
    return ResponseEnreplacedy.ok().contentType(MediaType.APPLICATION_ATOM_XML).cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).eTag(Utils.md5(feed)).body(feed);
}

16 View Source File : SearchController.java
License : Apache License 2.0
Project Creator : Erudika

@ResponseBody
@GetMapping("/opensearch.xml")
public ResponseEnreplacedy<String> openSearch() {
    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\" " + "  xmlns:moz=\"http://www.mozilla.org/2006/browser/search/\">\n" + "  <ShortName>" + Config.APP_NAME + "</ShortName>\n" + "  <Description>Search for questions and answers</Description>\n" + "  <InputEncoding>UTF-8</InputEncoding>\n" + "  <Image width=\"16\" height=\"16\" type=\"image/x-icon\">https://scoold.com/favicon.ico</Image>\n" + "  <Url type=\"text/html\" method=\"get\" template=\"" + ScooldServer.getServerURL() + CONTEXT_PATH + "/search?q={searchTerms}\"></Url>\n" + "</OpenSearchDescription>";
    return ResponseEnreplacedy.ok().contentType(MediaType.APPLICATION_XML).cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS)).eTag(Utils.md5(xml)).body(xml);
}

15 View Source File : HttpIT.java
License : Apache License 2.0
Project Creator : snowdrop

@Test
public void testCache() {
    startServerWithoutSecurity(CacheController.clreplaced);
    getWebTestClient().get().exchange().expectStatus().isOk().expectHeader().valueEquals(HttpHeaders.ETAG, "\"test\"").expectHeader().cacheControl(CacheControl.maxAge(1, TimeUnit.MINUTES)).expectBody(String.clreplaced).isEqualTo("test");
    getWebTestClient().get().header(HttpHeaders.IF_NONE_MATCH, "\"test\"").exchange().expectStatus().isNotModified();
}

15 View Source File : MasterDataController.java
License : Mozilla Public License 2.0
Project Creator : RadarCOVID

@Loggable
@GetMapping(path = { "/locales" }, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get availables locales", description = "Get availables locales", tags = { "masterData" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "successful operation", content = @Content(array = @ArraySchema(schema = @Schema(implementation = KeyValueDto.clreplaced)))), @ApiResponse(responseCode = "400", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "404", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "500", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))) })
public ResponseEnreplacedy<List<KeyValueDto>> getLocales(@RequestParam(value = "locale", required = false, defaultValue = DEFAULT_LOCALE) final String locale, @RequestParam(value = "platform", required = false) final String platform, @RequestParam(value = "version", required = false) final String version) {
    return ResponseEnreplacedy.status(HttpStatus.OK).cacheControl(CacheControl.maxAge(cacheLocales, TimeUnit.HOURS)).body(this.service.getLocales(locale, platform, version));
}

15 View Source File : MasterDataController.java
License : Mozilla Public License 2.0
Project Creator : RadarCOVID

@Loggable
@GetMapping(path = { "/countries" }, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get countries", description = "Get country list available", tags = { "masterData" })
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "successful operation", content = @Content(array = @ArraySchema(schema = @Schema(implementation = KeyValueDto.clreplaced)))), @ApiResponse(responseCode = "400", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "404", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))), @ApiResponse(responseCode = "500", description = "error", content = @Content(schema = @Schema(implementation = ErrorDto.clreplaced))) })
public ResponseEnreplacedy<List<KeyValueDto>> getCountries(@RequestParam(value = "locale", required = false, defaultValue = DEFAULT_LOCALE) final String locale, @RequestParam(value = "platform", required = false) final String platform, @RequestParam(value = "version", required = false) final String version) {
    return ResponseEnreplacedy.status(HttpStatus.OK).cacheControl(CacheControl.maxAge(cacheCountries, TimeUnit.HOURS)).body(this.service.getCountries(locale, platform, version));
}

15 View Source File : CatalogController.java
License : Apache License 2.0
Project Creator : making

@ResponseBody
@RequestMapping(method = HEAD, path = "images/{fileName:.+}")
public Mono<ResponseEnreplacedy<Resource>> headImage(@PathVariable String fileName) {
    return this.catalogClient.headImageWithFallback(fileName).map(body -> ResponseEnreplacedy.ok().cacheControl(CacheControl.maxAge(Duration.ofDays(7))).body(body));
}

15 View Source File : HaloMvcConfiguration.java
License : GNU General Public License v3.0
Project Creator : halo-dev

/**
 * Configuring static resource path
 *
 * @param registry registry
 */
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    String workDir = FILE_PROTOCOL + ensureSuffix(haloProperties.getWorkDir(), FILE_SEPARATOR);
    // register /** resource handler.
    registry.addResourceHandler("/**").addResourceLocations("clreplacedpath:/admin/").addResourceLocations(workDir + "static/");
    // register /themes/** resource handler.
    registry.addResourceHandler("/themes/**").addResourceLocations(workDir + "templates/themes/");
    String uploadUrlPattern = ensureBoth(haloProperties.getUploadUrlPrefix(), URL_SEPARATOR) + "**";
    String adminPathPattern = ensureSuffix(haloProperties.getAdminPath(), URL_SEPARATOR) + "**";
    registry.addResourceHandler(uploadUrlPattern).setCacheControl(CacheControl.maxAge(7L, TimeUnit.DAYS)).addResourceLocations(workDir + "upload/");
    registry.addResourceHandler(adminPathPattern).addResourceLocations("clreplacedpath:/admin/");
    // If doc is enable
    registry.addResourceHandler("swagger-ui.html").addResourceLocations("clreplacedpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("clreplacedpath:/META-INF/resources/webjars/");
}

14 View Source File : HeaderAssertionTests.java
License : MIT License
Project Creator : Vip-Augus

@Test
public void cacheControl() {
    CacheControl control = CacheControl.maxAge(1, TimeUnit.HOURS).noTransform();
    HttpHeaders headers = new HttpHeaders();
    headers.setCacheControl(control.getHeaderValue());
    Headerreplacedertions replacedertions = headerreplacedertions(headers);
    // Success
    replacedertions.cacheControl(control);
    try {
        replacedertions.cacheControl(CacheControl.noStore());
        fail("Wrong value expected");
    } catch (replacedertionError error) {
    // Expected
    }
}

14 View Source File : FirebaseJwtTokenDecoderTests.java
License : Apache License 2.0
Project Creator : spring-cloud

private RestOperations mockRestOperations() throws Exception {
    Map<String, String> payload = new HashMap<>();
    payload.put("one", keyGeneratorUtils.getPublicKeyCertificate());
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CACHE_CONTROL, CacheControl.maxAge(3600L, TimeUnit.SECONDS).getHeaderValue());
    ResponseEnreplacedy<Map<String, String>> response = new ResponseEnreplacedy<>(payload, headers, HttpStatus.OK);
    return mockRestOperations(response);
}

14 View Source File : HeaderAssertionTests.java
License : Apache License 2.0
Project Creator : SourceHot

@Test
public void cacheControl() {
    CacheControl control = CacheControl.maxAge(1, TimeUnit.HOURS).noTransform();
    HttpHeaders headers = new HttpHeaders();
    headers.setCacheControl(control.getHeaderValue());
    Headerreplacedertions replacedertions = headerreplacedertions(headers);
    // Success
    replacedertions.cacheControl(control);
    // Wrong value
    replacedertThatExceptionOfType(replacedertionError.clreplaced).isThrownBy(() -> replacedertions.cacheControl(CacheControl.noStore()));
}

14 View Source File : WebConfig.java
License : MIT License
Project Creator : PaperMC

// TODO remove after freemarker is gone
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    VersionResourceResolver resolver = new VersionResourceResolver().addContentVersionStrategy("/**");
    registry.addResourceHandler("/replacedets/**").addResourceLocations("clreplacedpath:/public/").setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)).resourceChain(true).addResolver(resolver).addTransformer(new CssLinkResourceTransformer());
}

See More Examples