标签:3.1 因此 serve 效果 两种 pos power omv utf-8
@Override
public void onClick(View view) {
if (view.getId() == R.id.button) {
Observable.interval(3, TimeUnit.SECONDS).subscribe(
new Action1<Long>() {
@Override
public void call(Long aLong) {
getRecomandComic();
}
}
);
}
}
private void getRecomandComic() {
RetrofitResearch.getInstance(this)
.getTopRecommendList()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<ComicBeanNoCountResult>() {
@Override
public void call(ComicBeanNoCountResult comicBeanNoCountResult) {
}
},
new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
}
});
}
|
public class OkHttpCallFactory {
private static int DEFAULT_TIMEOUT = 30;
private static final int CONST_10 = 10;
private static final int CONST_1024 = 1024;
private static final Logger logger = Logger.getLogger("yansm");
private OkHttpCallFactory() {
}
private static Call.Factory factory;
private static int time =60;
public static Call.Factory getOkHttpFactory(Context context) {
if (factory == null) {
synchronized (OkHttpCallFactory.class) {
if (factory == null) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.cache(new Cache(context.getCacheDir(),
CONST_10 * CONST_1024 * CONST_1024)); //设置缓存
builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
builder.writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
builder.readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
Interceptor interceptor = new NetCacheInterceptor();
builder.addInterceptor(interceptor);
builder.addNetworkInterceptor(interceptor);
builder.addInterceptor(new LoggingInterceptor());
factory = builder.build();
}
}
}
return factory;
}
//日志输出的拦截器
private static class LoggingInterceptor implements Interceptor {
@Override public Response intercept(Chain chain) throws IOException {
long t1 = System.nanoTime();
Request request = chain.request();
logger.info(String.format("Sending request %s on %s%n%s",
request.url(), chain.connection(), request.headers()));
Response response = chain.proceed(request);
long t2 = System.nanoTime();
logger.info(String.format("Received response for %s in %.1fms%n%s",
request.url(), (t2 - t1) / 1e6d, response.headers()));
return response;
}
}
}
|
public class NetCacheInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
CacheControl cacheControl = new CacheControl.Builder()
.maxAge(60, TimeUnit.SECONDS)
.maxStale(120, TimeUnit.SECONDS).build();
Response response = chain.proceed(request);
return response.newBuilder()
.removeHeader("Pragma")
.removeHeader("Cache-Control")
.header("Cache-Control", cacheControl.toString())
.build();
}
}
|
第一次网络请求
06-22 13:59:51.816 32336-469/com.example.moxie.cacheresearch I/yansm: Sending request http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network on null
06-22 13:59:52.200 32336-469/com.example.moxie.cacheresearch I/yansm: Received response for http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network in 381.9ms
Server: Tengine
Content-Type: text/json;charset=UTF-8
Content-Length: 1492
Date: Fri, 22 Jun 2018 05:59:51 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
X-Powered-By: PHP/7.0.1
Set-Cookie: PHPSESSID=pef8qomvm3kjg90bs94ojpugf1; path=/
Set-Cookie: SERVERID=37f80876073565188d4968aa47392891|1529647191|1529647191;Path=/
Via: cache14.l2eu6-1[103,200-0,M], cache4.l2eu6-1[103,0], cache8.cn785[155,200-0,M], cache7.cn785[159,0]
X-Cache: MISS TCP_MISS dirn:-2:-2 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 05:59:51 GMT
X-Swift-CacheTime: 0
Timing-Allow-Origin: *
EagleId: 3d9bde1b15296471912141111e
Connection: keep-alive
Cache-Control: max-age=60, max-stale=120
第二次网络请求
06-22 13:59:54.733 32336-469/com.example.moxie.cacheresearch I/yansm: Sending request http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network on null
06-22 13:59:54.759 32336-469/com.example.moxie.cacheresearch I/yansm: Received response for http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network in 25.1ms
Server: Tengine
Content-Type: text/json;charset=UTF-8
Content-Length: 1492
Date: Fri, 22 Jun 2018 05:59:51 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
X-Powered-By: PHP/7.0.1
Set-Cookie: PHPSESSID=pef8qomvm3kjg90bs94ojpugf1; path=/
Set-Cookie: SERVERID=37f80876073565188d4968aa47392891|1529647191|1529647191;Path=/
Via: cache14.l2eu6-1[103,200-0,M], cache4.l2eu6-1[103,0], cache8.cn785[155,200-0,M], cache7.cn785[159,0]
X-Cache: MISS TCP_MISS dirn:-2:-2 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 05:59:51 GMT
X-Swift-CacheTime: 0
Timing-Allow-Origin: *
EagleId: 3d9bde1b15296471912141111e
Connection: keep-alive
Cache-Control: max-age=60, max-stale=120
第三次网络请求
06-22 13:59:57.733 32336-469/com.example.moxie.cacheresearch I/yansm: Sending request http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network on null
06-22 13:59:57.749 32336-469/com.example.moxie.cacheresearch I/yansm: Received response for http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network in 14.9ms
Server: Tengine
Content-Type: text/json;charset=UTF-8
Content-Length: 1492
Date: Fri, 22 Jun 2018 05:59:51 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
X-Powered-By: PHP/7.0.1
Set-Cookie: PHPSESSID=pef8qomvm3kjg90bs94ojpugf1; path=/
Set-Cookie: SERVERID=37f80876073565188d4968aa47392891|1529647191|1529647191;Path=/
Via: cache14.l2eu6-1[103,200-0,M], cache4.l2eu6-1[103,0], cache8.cn785[155,200-0,M], cache7.cn785[159,0]
X-Cache: MISS TCP_MISS dirn:-2:-2 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 05:59:51 GMT
X-Swift-CacheTime: 0
Timing-Allow-Origin: *
EagleId: 3d9bde1b15296471912141111e
Connection: keep-alive
Cache-Control: max-age=60, max-stale=120
|
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
CacheControl cacheControl = new CacheControl.Builder().maxAge(120, TimeUnit.SECONDS)
.maxStale(60, TimeUnit.SECONDS).build();
request = request.newBuilder()
.cacheControl(cacheControl)
.build();
return chain.proceed(request);
}
|
第一次网络请求
06-22 13:33:28.131 29674-30389/com.example.moxie.cacheresearch I/yansm: Sending request http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network on null
Cache-Control: max-age=120, max-stale=60
06-22 13:33:28.700 29674-30389/com.example.moxie.cacheresearch I/yansm: Received response for http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network in 567.5ms
Server: Tengine
Content-Type: text/json;charset=UTF-8
Content-Length: 1492
Date: Fri, 22 Jun 2018 05:33:27 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
X-Powered-By: PHP/7.0.1
Set-Cookie: PHPSESSID=t6j4tnss1nkpbm0tddqdr0o2j1; path=/
Set-Cookie: SERVERID=37f80876073565188d4968aa47392891|1529645607|1529645607;Path=/
Via: cache14.l2eu6-1[102,200-0,M], cache21.l2eu6-1[106,0], cache10.cn883[190,200-0,M], cache1.cn883[214,0]
X-Cache: MISS TCP_MISS dirn:-2:-2 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 05:33:27 GMT
X-Swift-CacheTime: 0
Timing-Allow-Origin: *
EagleId: af06f99515296456075954226e
Connection: keep-alive
Cache-Control: public, max-age=6000
第N次网络请求
06-22 13:35:25.057 29674-30389/com.example.moxie.cacheresearch I/yansm: Received response for http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network in 9.6ms
Server: Tengine
Content-Type: text/json;charset=UTF-8
Content-Length: 1492
Date: Fri, 22 Jun 2018 05:33:27 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
X-Powered-By: PHP/7.0.1
Set-Cookie: PHPSESSID=t6j4tnss1nkpbm0tddqdr0o2j1; path=/
Set-Cookie: SERVERID=37f80876073565188d4968aa47392891|1529645607|1529645607;Path=/
Via: cache14.l2eu6-1[102,200-0,M], cache21.l2eu6-1[106,0], cache10.cn883[190,200-0,M], cache1.cn883[214,0]
X-Cache: MISS TCP_MISS dirn:-2:-2 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 05:33:27 GMT
X-Swift-CacheTime: 0
Timing-Allow-Origin: *
EagleId: af06f99515296456075954226e
Connection: keep-alive
Cache-Control: public, max-age=6000
第N+1次网络请求
06-22 13:35:28.046 29674-30389/com.example.moxie.cacheresearch I/yansm: Sending request http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network on null
Cache-Control: max-age=120, max-stale=60
06-22 13:35:28.056 29674-30389/com.example.moxie.cacheresearch I/yansm: Received response for http://lbs.sougu.net.cn/app.php?m=souguapp&c=appusers&a=network in 8.9ms
Server: Tengine
Content-Type: text/json;charset=UTF-8
Content-Length: 1492
Date: Fri, 22 Jun 2018 05:33:27 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
X-Powered-By: PHP/7.0.1
Set-Cookie: PHPSESSID=t6j4tnss1nkpbm0tddqdr0o2j1; path=/
Set-Cookie: SERVERID=37f80876073565188d4968aa47392891|1529645607|1529645607;Path=/
Via: cache14.l2eu6-1[102,200-0,M], cache21.l2eu6-1[106,0], cache10.cn883[190,200-0,M], cache1.cn883[214,0]
X-Cache: MISS TCP_MISS dirn:-2:-2 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 05:33:27 GMT
X-Swift-CacheTime: 0
Timing-Allow-Origin: *
EagleId: af06f99515296456075954226e
Connection: keep-alive
Cache-Control: public, max-age=6000
Warning: 110 HttpURLConnection "Response is stale"
|
第一次网络请求
06-22 17:38:27.094 7756-7780/com.example.moxie.cacheresearch I/yansm: Sending request https://comic.mkzhan.com/recom/app/ on null
06-22 17:38:27.253 7756-7780/com.example.moxie.cacheresearch I/yansm: Received response for https://comic.mkzhan.com/recom/app/ in 158.0ms
Server: Tengine
Content-Type: application/json; charset=utf-8
Content-Length: 625
Date: Fri, 22 Jun 2018 08:51:34 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With,app-id,app-version,device-name,device-resolution,device-udid,platform,system-name,system-version
Access-Control-Allow-Methods: GET,POST,OPTIONS
X-Powered-By: mkzhan-A2
Via: cache9.l2cm10-1[0,200-0,H], cache29.l2cm10-1[1,0], cache1.cn1412[0,200-0,H], cache14.cn1412[1,0]
Age: 2812
X-Cache: HIT TCP_MEM_HIT dirn:12:43491335 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 09:03:10 GMT
X-Swift-CacheTime: 3600
Timing-Allow-Origin: *
EagleId: 7ce89ea215296603064393222e
Connection: keep-alive
Cache-Control: max-age=60, max-stale=120
第二次网络请求
06-22 17:38:30.091 7756-7780/com.example.moxie.cacheresearch I/yansm: Sending request https://comic.mkzhan.com/recom/app/ on null
06-22 17:38:30.249 7756-7780/com.example.moxie.cacheresearch I/yansm: Received response for https://comic.mkzhan.com/recom/app/ in 156.9ms
Server: Tengine
Content-Type: application/json; charset=utf-8
Content-Length: 625
Date: Fri, 22 Jun 2018 08:51:34 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With,app-id,app-version,device-name,device-resolution,device-udid,platform,system-name,system-version
Access-Control-Allow-Methods: GET,POST,OPTIONS
X-Powered-By: mkzhan-A2
Via: cache9.l2cm10-1[0,200-0,H], cache29.l2cm10-1[1,0], cache1.cn1412[0,200-0,H], cache14.cn1412[1,0]
Age: 2815
X-Cache: HIT TCP_MEM_HIT dirn:12:43491335 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 09:03:10 GMT
X-Swift-CacheTime: 3600
Timing-Allow-Origin: *
EagleId: 7ce89ea215296603094162696e
Connection: keep-alive
Cache-Control: max-age=60, max-stale=120
第三次网络请求
06-22 17:38:33.093 7756-7780/com.example.moxie.cacheresearch I/yansm: Sending request https://comic.mkzhan.com/recom/app/ on null
06-22 17:38:33.198 7756-7780/com.example.moxie.cacheresearch I/yansm: Received response for https://comic.mkzhan.com/recom/app/ in 103.4ms
Server: Tengine
Content-Type: application/json; charset=utf-8
Content-Length: 625
Date: Fri, 22 Jun 2018 08:51:34 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With,app-id,app-version,device-name,device-resolution,device-udid,platform,system-name,system-version
Access-Control-Allow-Methods: GET,POST,OPTIONS
X-Powered-By: mkzhan-A2
Via: cache9.l2cm10-1[0,200-0,H], cache29.l2cm10-1[1,0], cache1.cn1412[0,200-0,H], cache14.cn1412[0,0]
Age: 2818
X-Cache: HIT TCP_MEM_HIT dirn:12:43491335 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 09:03:10 GMT
X-Swift-CacheTime: 3600
Timing-Allow-Origin: *
EagleId: 7ce89ea215296603123821715e
Connection: keep-alive
Cache-Control: max-age=60, max-stale=120
|
06-22 09:52:47.578 14683-14855/com.example.moxie.cacheresearch I/yansm: Sending request https://comic.mkzhan.com/recom/app/ on null
06-22 09:52:48.216 14683-14855/com.example.moxie.cacheresearch I/yansm: Received response for https://comic.mkzhan.com/recom/app/ in 637.9ms
Server: Tengine
Content-Type: application/json; charset=utf-8
Content-Length: 624
Date: Fri, 22 Jun 2018 00:51:28 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With,app-id,app-version,device-name,device-resolution,device-udid,platform,system-name,system-version
Access-Control-Allow-Methods: GET,POST,OPTIONS
X-Powered-By: mkzhan-A2
Via: cache9.l2cm10-1[0,200-0,H], cache22.l2cm10-1[1,0], cache10.cn978[0,200-0,H], cache2.cn978[1,0]
Age: 3679
X-Cache: HIT TCP_MEM_HIT dirn:6:301393262 mlen:-1
X-Swift-SaveTime: Fri, 22 Jun 2018 01:08:57 GMT
X-Swift-CacheTime: 3600
Timing-Allow-Origin: *
EagleId: 74d3999615296323674053464e
Connection: keep-alive
Cache-Control: public, max-age=4000
|
标签:3.1 因此 serve 效果 两种 pos power omv utf-8
原文地址:https://www.cnblogs.com/polo2044/p/9217043.html