Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/main/java/se/michaelthelin/spotify/SpotifyHttpManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -140,6 +140,10 @@ public Integer getCacheMaxObjectSize() {
return cacheMaxObjectSize;
}

public Boolean getCacheShared() {
return cacheShared;
}

public Integer getConnectionRequestTimeout() {
return connectionRequestTimeout;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Loading