當前位置: 首頁>>代碼示例>>Java>>正文


Java ResponseCacheMiddleware.clear方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:jacklongway,項目名稱:LiteSDK,代碼行數:33,代碼來源:CacheTests.java

示例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);
    }
}
 
開發者ID:jacklongway,項目名稱:LiteSDK,代碼行數:16,代碼來源:HttpClientTests.java


注:本文中的com.koushikdutta.async.http.cache.ResponseCacheMiddleware.clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。