Skip to content

Commit

Permalink
fix: Make the LRU map synchronized to keep cache thread safe. (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
psantos1113 authored Jun 10, 2022
1 parent c5871b9 commit b74267a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.nio.charset.Charset;
import java.util.Map;

import org.apache.commons.collections4.map.LRUMap;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;

Expand All @@ -24,11 +23,11 @@
public class CacheableResponse implements Response {
private final Request request;
private final Response response;
private final LRUMap<Request, Response> cache;
private final Map<Request, Response> cache;

private String stringResponse;

public CacheableResponse(Request request, Response response, LRUMap<Request, Response> cache) {
public CacheableResponse(Request request, Response response, Map<Request, Response> cache) {
this.request = request;
this.response = response;
this.cache = cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
package com.synopsys.integration.blackduck.http.client.cache;

import java.util.Collections;
import java.util.Map;
import java.util.Optional;

import org.apache.commons.collections4.map.LRUMap;
Expand All @@ -29,11 +31,11 @@

public class CachingHttpClient implements BlackDuckHttpClient {
private final BlackDuckHttpClient blackDuckHttpClient;
private final LRUMap<Request, Response> cache;
private final Map<Request, Response> cache;

public CachingHttpClient(BlackDuckHttpClient blackDuckHttpClient) {
this.blackDuckHttpClient = blackDuckHttpClient;
this.cache = new LRUMap<>(1000);
this.cache = Collections.synchronizedMap(new LRUMap<>(1000));
}

public void emptyCache() {
Expand Down

0 comments on commit b74267a

Please sign in to comment.