diff --git a/src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java b/src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java index 5a9dcfae2..5d579e910 100644 --- a/src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java +++ b/src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java @@ -33,8 +33,6 @@ public class SpotifyHttpManager implements IHttpManager { - private static final int DEFAULT_CACHE_MAX_ENTRIES = 1000; - private static final int DEFAULT_CACHE_MAX_OBJECT_SIZE = 8192; private static final Gson GSON = new Gson(); private final CloseableHttpClient httpClient; private final CloseableHttpClient httpClientCaching; @@ -43,6 +41,7 @@ public class SpotifyHttpManager implements IHttpManager { private final UsernamePasswordCredentials proxyCredentials; private final Integer cacheMaxEntries; private final Integer cacheMaxObjectSize; + private final Boolean cacheShared; private final Integer connectionRequestTimeout; private final Integer socketTimeout; @@ -57,13 +56,14 @@ public SpotifyHttpManager(Builder builder) { this.proxyCredentials = builder.proxyCredentials; this.cacheMaxEntries = builder.cacheMaxEntries; this.cacheMaxObjectSize = builder.cacheMaxObjectSize; + this.cacheShared = builder.cacheShared; this.connectionRequestTimeout = builder.connectionRequestTimeout; this.socketTimeout = builder.socketTimeout; CacheConfig cacheConfig = CacheConfig.custom() - .setMaxCacheEntries(cacheMaxEntries != null ? cacheMaxEntries : DEFAULT_CACHE_MAX_ENTRIES) - .setMaxObjectSize(cacheMaxObjectSize != null ? cacheMaxObjectSize : DEFAULT_CACHE_MAX_OBJECT_SIZE) - .setSharedCache(false) + .setMaxCacheEntries(cacheMaxEntries) + .setMaxObjectSize(cacheMaxObjectSize) + .setSharedCache(cacheShared) .build(); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); @@ -140,6 +140,10 @@ public Integer getCacheMaxObjectSize() { return cacheMaxObjectSize; } + public Boolean getCacheShared() { + return cacheShared; + } + public Integer getConnectionRequestTimeout() { return connectionRequestTimeout; } @@ -354,8 +358,9 @@ public static class Builder { private HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); private HttpHost proxy; private UsernamePasswordCredentials proxyCredentials; - private Integer cacheMaxEntries; - private Integer cacheMaxObjectSize; + private Integer cacheMaxEntries = CacheConfig.DEFAULT_MAX_CACHE_ENTRIES; + private Integer cacheMaxObjectSize = CacheConfig.DEFAULT_MAX_OBJECT_SIZE_BYTES; + private Boolean cacheShared = Boolean.FALSE; private Integer connectionRequestTimeout; private Integer socketTimeout; @@ -384,6 +389,11 @@ public Builder setCacheMaxObjectSize(Integer cacheMaxObjectSize) { return this; } + public Builder setCacheShared(Boolean cacheShared) { + this.cacheShared = cacheShared; + return this; + } + public Builder setConnectionRequestTimeout(Integer connectionRequestTimeout) { this.connectionRequestTimeout = connectionRequestTimeout; return this;