本文整理匯總了Java中com.koushikdutta.async.http.cache.ResponseCacheMiddleware.addCache方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseCacheMiddleware.addCache方法的具體用法?Java ResponseCacheMiddleware.addCache怎麽用?Java ResponseCacheMiddleware.addCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.koushikdutta.async.http.cache.ResponseCacheMiddleware
的用法示例。
在下文中一共展示了ResponseCacheMiddleware.addCache方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: addCache
import com.koushikdutta.async.http.cache.ResponseCacheMiddleware; //導入方法依賴的package包/類
@Override
public void addCache(File dir, int maxSize) {
if (mResponseCacheMiddleware == null) {
try {
mResponseCacheMiddleware = ResponseCacheMiddleware.addCache(HttpApi.asyncHttpClient, dir, maxSize);
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例3: 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);
}
}