简体   繁体   English

缓存控制被忽略

[英]Cache Control gets ignored

I am currently working with Retrofit and Okhttp and I am trying to cache some GET responses. 我目前正在使用Retrofit和Okhttp,并且正在尝试缓存一些GET响应。 My Code is: 我的代码是:

OkHttpClient okHttpClient = new OkHttpClient();
    File cacheDir = new File(System.getProperty("java.io.tmpdir"),
            "ddcache");
    HttpResponseCache cache = new HttpResponseCache(cacheDir, 2024);
    okHttpClient.setResponseCache(cache);
    OkClient cl=new OkClient(okHttpClient);
    restAdapter = new RestAdapter.Builder().setEndpoint(API_URL)
            .setLogLevel(RestAdapter.LogLevel.FULL)
            .setClient(cl).build();

And the Log shows this header: 日志显示此标头:

HTTP/1.1 200 OK
Cache-Control: max-age=7200
Connection: Keep-Alive
Content-Type: text/html
Date: Tue, 18 Mar 2014 18:38:16 GMT
Keep-Alive: timeout=3, max=100
OkHttp-Received-Millis: 1395167895452
OkHttp-Response-Source: NETWORK 200
OkHttp-Sent-Millis: 1395167895378
Server: Apache/2.2.26 (Unix)
Transfer-Encoding: chunked
X-Powered-By: PHP/5.3.28

I check the response by returning the Server Unix Time on every call and it always returns a new one which means the 我通过在每次调用时返回服务器Unix时间来检查响应,并且它总是返回一个新值,这意味着

Cache-Control: max-age=7200 快取控制:max-age = 7200

gets totally ignored The Journal File in the Cache gets also updated with "CLEAN" and "DIRTY" notes, but nothing gets cached. 被完全忽略缓存中的日记文件也使用“ CLEAN”和“ DIRTY”注释进行了更新,但是没有任何缓存。 Is there something obvious I do not see? 有什么明显的我看不到的东西吗?

I think I had a similar problem. 我想我也有类似的问题。 The size of the cache is set in kilobytes and you are setting it to only 2024 kilobytes. 缓存的大小以千字节为单位设置,而您将其设置为仅2024千字节。 That not enough space for almost anything. 几乎没有什么空间可用。 Try setting it to "10L * 1024 * 1024" (10Mb) and see if that helps. 尝试将其设置为“ 10L * 1024 * 1024”(10Mb),看看是否有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM