本文整理汇总了Java中com.koushikdutta.async.http.cache.ResponseCacheMiddleware.clear方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseCacheMiddleware.clear方法的具体用法?Java ResponseCacheMiddleware.clear怎么用?Java ResponseCacheMiddleware.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.koushikdutta.async.http.cache.ResponseCacheMiddleware
的用法示例。
在下文中一共展示了ResponseCacheMiddleware.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMaxAgePrivate
import com.koushikdutta.async.http.cache.ResponseCacheMiddleware; //导入方法依赖的package包/类
public void testMaxAgePrivate() throws Exception {
AsyncHttpClient client = new AsyncHttpClient(AsyncServer.getDefault());
ResponseCacheMiddleware cache = ResponseCacheMiddleware.addCache(client, new File(getContext().getFilesDir(), "AndroidAsyncTest"), 1024 * 1024 * 10);
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.get("/uname/(.*)", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.getHeaders().set("Date", HttpDate.format(new Date()));
response.getHeaders().set("Cache-Control", "private, max-age=10000");
response.send(request.getMatcher().group(1));
}
});
AsyncServerSocket socket = httpServer.listen(AsyncServer.getDefault(), 0);
int port = socket.getLocalPort();
// clear the old cache
cache.clear();
client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();
client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();
assertEquals(cache.getCacheHitCount(), 1);
assertEquals(cache.getNetworkCount(), 1);
}
finally {
AsyncServer.getDefault().stop();
client.getMiddleware().remove(cache);
}
}
示例2: testCache
import com.koushikdutta.async.http.cache.ResponseCacheMiddleware; //导入方法依赖的package包/类
public void testCache() throws Exception {
ResponseCacheMiddleware cache = ResponseCacheMiddleware.addCache(client, new File(getContext().getFilesDir(), "AndroidAsyncTest"), 1024 * 1024 * 10);
try {
// clear the old cache
cache.clear();
// populate the cache
testGithubRandomData();
// this should result in a conditional cache hit
testGithubRandomData();
assertEquals(cache.getCacheHitCount(), 1);
}
finally {
client.getMiddleware().remove(cache);
}
}