3
我一直在測試改造緩存。我正在使用retrofit2.0.0 beta2和okhttp:3.2.0。這是我的代碼。改造緩存504不可訪問請求(僅緩存)錯誤
final Cache cache = new Cache(new File(context.getCacheDir(), CACHE_DIR), CACHE_SIZE);
String cachePath = cache.getDirectory().getPath();
OkHttpClient okClient = new OkHttpClient();
okClient.setCache(cache);
okClient.interceptors().add(logging);
String FORCE_CACHE_HEADERS = "Cache-Control: public, only-if-cached, max-stale=" + Integer.MAX_VALUE;
@GET("/")Call<RES> GETve(@QueryMap Map<String, String> params);
@Headers({FORCE_CACHE_HEADERS})@GET("/")Call<RES> GETCacheve(@QueryMap Map<String, String> params);
第一個請求是好的。
###Logging : --> GET https://xxx
###Logging : --> END GET
###OkHttpClient response : Response{protocol=http/1.1, code=200, message=OK, url=https://xxx
###OkHttpClient response.cacheControl() : no-cache, public, max-stale=2419200
###OkHttpClient response.cacheResponse() : null
###Logging : <-- HTTP/1.1 200 OK (133ms)
###Logging : Date: Mon, 11 Apr 2016 06:52:46 GMT
###Logging : Server: Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_jk/1.2.37
###Logging : Pragma: no-cache
###Logging : Expires: Thu, 01 Jan 1970 00:00:00 GMT
###Logging : Content-Length: 190
###Logging : Keep-Alive: timeout=5, max=100
###Logging : Connection: Keep-Alive
###Logging : Content-Type: text/html;charset=euc-kr
###Logging : Content-Language: euc-kr
###Logging : OkHttp-Sent-Millis: 1460357566280
###Logging : OkHttp-Received-Millis: 1460357566290
###Logging : Cache-Control: public, max-stale=2419200
###Logging : <-- END HTTP (190-byte body)
###response.code() : 200, isSuccess() : true
第二請求生成504錯誤。
###Logging : --> GET https://xxx HTTP/1.1
###Logging : Cache-Control: public, only-if-cached, max-stale=2147483647
###Logging : --> END GET
###OkHttpClient response : Response{protocol=http/1.1, code=504, message=Unsatisfiable Request (only-if-cached), url=https://xxx
###OkHttpClient response.cacheControl() :
###OkHttpClient response.cacheResponse() : null
###Logging : <-- HTTP/1.1 504 Unsatisfiable Request (only-if-cached) (3ms)
###Logging : <-- END HTTP (0-byte body)
我試圖刪除附註。但是,一樣。和 結果使用後的男人,
的Cache-Control→無店鋪
附註→無緩存
爲什麼會造成這種不可滿足504請求(只,如果緩存的)錯誤? 我該如何解決這個錯誤?