okhttpのCacheControl.Builder.maxStale()の挙動を誤解してた。リクエストにCacheControl.Builder.maxStaleを指定するとageがstale期限内であればネットワークアクセスは行われないのだった。
Conversation
Notices
-
tateisu :force::r_9a: (tateisu@mastodon.juggler.jp)'s status on Wednesday, 16-Jan-2019 00:57:44 JST
tateisu :force::r_9a:
-
tateisu :force::r_9a: (tateisu@mastodon.juggler.jp)'s status on Wednesday, 16-Jan-2019 01:00:32 JST
tateisu :force::r_9a:
okhttpのリポジトリをgit cloneしてandroid studioで超適当に開く。
CacheControl.Builder.maxStale()経由でセットされるCacheControl.maxStaleSeconds() をFind Usages
CacheStrategy.Factory.getCandidate()で使われてる。
- mustRevalidate() が偽
- noCache()が偽
- maxStaleSeconds()が-1ではない
- ageMillis + minFreshMillis < freshMillis + maxStaleMillis
上記条件をすべて満たすとネットワークアクセスなしでキャッシュレスポンスを返す。
さらにFind Usagesを辿ると CacheInterceptor.intercept() が CacheStrategy.Factory.get() を呼び出す。
RealCall.getResponseWithInterceptorChain() が CacheInterceptor を生成する。
-