当前位置: 首页>>代码示例>>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;未经允许,请勿转载。