diff --git a/build.gradle b/build.gradle index d1830f7..68ede34 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,8 @@ group 'com.wego' version '1.0.1' apply plugin: 'java' +apply plugin: 'maven' +apply plugin: 'checkstyle' sourceCompatibility = '1.8' targetCompatibility = '1.8' @@ -10,10 +12,6 @@ task wrapper(type: Wrapper) { gradleVersion = '2.8' } -apply plugin: 'maven' - -apply plugin: 'checkstyle' - repositories { mavenCentral() } diff --git a/src/main/java/com/wego/httpcache/services/impl/AsyncHttpCacheServiceImpl.java b/src/main/java/com/wego/httpcache/services/impl/AsyncHttpCacheServiceImpl.java index a9a3c9d..ca640e0 100644 --- a/src/main/java/com/wego/httpcache/services/impl/AsyncHttpCacheServiceImpl.java +++ b/src/main/java/com/wego/httpcache/services/impl/AsyncHttpCacheServiceImpl.java @@ -17,15 +17,16 @@ public class AsyncHttpCacheServiceImpl implements AsyncHttpCacheService { - @Inject - private CachedResponseService cachedResponseService; - + private static final String DELIMITER = ":"; + @Inject private CachedResponseService cachedResponseService; + private String serviceName; private AsyncHttpClient asyncHttpClient; - private long ttl; @Inject - public AsyncHttpCacheServiceImpl(@Assisted AsyncHttpClient asyncHttpClient, @Assisted long ttl) { + public AsyncHttpCacheServiceImpl( + @Assisted String serviceName, @Assisted AsyncHttpClient asyncHttpClient, @Assisted long ttl) { + this.serviceName = serviceName; this.asyncHttpClient = asyncHttpClient; this.ttl = ttl; } @@ -59,10 +60,9 @@ public Optional> executeRequest( private String buildResponseId(Request request) { String requestStringId = StringUtils.join( - request, - request.getStringData(), - Lists.newArrayList(request.getCookies()).toString()); - return String.valueOf(MurmurHash.hash64A(requestStringId.getBytes(), 0)); + request, request.getStringData(), Lists.newArrayList(request.getCookies()).toString()); + return StringUtils.joinWith( + DELIMITER, serviceName, String.valueOf(MurmurHash.hash64A(requestStringId.getBytes(), 0))); } private AsyncCompletionHandlerBase buildCachingHandler( diff --git a/src/test/java/com/wego/httpcache/services/impl/TestAsyncHttpCacheServiceImpl.java b/src/test/java/com/wego/httpcache/services/impl/TestAsyncHttpCacheServiceImpl.java index c60215c..07af9bf 100644 --- a/src/test/java/com/wego/httpcache/services/impl/TestAsyncHttpCacheServiceImpl.java +++ b/src/test/java/com/wego/httpcache/services/impl/TestAsyncHttpCacheServiceImpl.java @@ -44,6 +44,8 @@ @RunWith(MockitoJUnitRunner.class) public class TestAsyncHttpCacheServiceImpl { + private final static String SERVICE_NAME = "Service Name"; + private static long CACHING_TTL = 60; @Rule public WireMockRule wireMockRule = new WireMockRule(8089); @@ -53,7 +55,7 @@ public class TestAsyncHttpCacheServiceImpl { @InjectMocks private AsyncHttpCacheService asyncHttpCacheService = - new AsyncHttpCacheServiceImpl(asyncHttpClient, CACHING_TTL); + new AsyncHttpCacheServiceImpl(SERVICE_NAME, asyncHttpClient, CACHING_TTL); @Mock private CachedResponseService cachedResponseService; @@ -235,6 +237,7 @@ public void buildResponseId_returnsDifferentIdsForDifferentRequest() throws Exce .collect(Collectors.toList()); assertThat(Sets.newHashSet(responseIds).size()).isEqualTo(13); + assertThat(responseIds.get(0)).startsWith(SERVICE_NAME); } @Test