/**
* Equivalent to {@code CacheTest.postInvalidatesCacheWithUncacheableResponse()} but demonstrating
* that {@link ResponseCache} provides no mechanism for cache invalidation as the result of
* locally-made requests. In reality invalidation could take place from other clients at any
* time.
*/
@Test public void postInvalidatesCacheWithUncacheableResponse() throws Exception {
// 1. seed the cache
// 2. invalidate it with uncacheable response
// 3. the cache to return the original value
server.enqueue(new MockResponse()
.setBody("A")
.addHeader("Expires: " + formatDate(1, TimeUnit.HOURS)));
server.enqueue(new MockResponse()
.setBody("B")
.setResponseCode(500));
URL url = server.url("/").url();
assertEquals("A", readAscii(openConnection(url)));
HttpURLConnection invalidate = openConnection(url);
invalidate.setRequestMethod("POST");
addRequestBodyIfNecessary("POST", invalidate);
assertEquals("B", readAscii(invalidate));
assertEquals("A", readAscii(openConnection(url)));
}
ResponseCacheTest.java 文件源码
java
阅读 32
收藏 0
点赞 0
评论 0
项目:GitHub
作者:
评论列表
文章目录