diff options
author | Vitaly Takmazov | 2018-10-24 01:07:30 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-10-24 01:07:30 +0300 |
commit | 82de22618ef0e95450ce43fa519ed1203d256674 (patch) | |
tree | d9c98315f0527f5537795c3b1fc2a1c280f3d96a /juick-server/src/main/java/com/juick/server/configuration | |
parent | aa4dab444166f530adcd86003f802350db44b0b1 (diff) |
ActivityPub: cache requests
Diffstat (limited to 'juick-server/src/main/java/com/juick/server/configuration')
-rw-r--r-- | juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java b/juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java new file mode 100644 index 00000000..b7762221 --- /dev/null +++ b/juick-server/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java @@ -0,0 +1,40 @@ +package com.juick.server.configuration; + +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.cache.CacheConfig; +import org.apache.http.impl.client.cache.CachingHttpClientBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class ActivityPubClientConfig { + @Bean + public RestTemplate apClient() { + SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); + RestTemplate restTemplate = new RestTemplate(requestFactory); + // BufferingClientHttpRequestFactory allows us to read the response more than once - Necessary for debugging. + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient()))); + return restTemplate; + } + @Bean + public HttpClient httpClient() { + return CachingHttpClientBuilder + .create() + .setCacheConfig(cacheConfig()) + .build(); + } + @Bean + public CacheConfig cacheConfig() { + return CacheConfig + .custom() + .setMaxObjectSize(500000) // 500KB + .setMaxCacheEntries(2000) + // Set this to false and a response with queryString + // will be cached when it is explicitly cacheable .setNeverCacheHTTP10ResponsesWithQueryString(false) + .build(); + } +}
\ No newline at end of file |