Example usage for com.squareup.okhttp Request cacheControl

List of usage examples for com.squareup.okhttp Request cacheControl

Introduction

In this page you can find the example usage for com.squareup.okhttp Request cacheControl.

Prototype

CacheControl cacheControl

To view the source code for com.squareup.okhttp Request cacheControl.

Click Source Link

Usage

From source file:com.kubeiwu.easyandroid.easyhttp.core.retrofit.GsonConverter.java

License:Apache License

private void parseCache(Request request, T object, String string, String mimeType)
        throws UnsupportedEncodingException {
    com.squareup.okhttp.CacheControl cacheControl = request.cacheControl();
    if (cacheControl != null) {
        if (!cacheControl.noCache() && !cacheControl.noStore()) {
            if (object instanceof EAResult) {
                EAResult kResult = (EAResult) object;
                if (kResult != null && kResult.isSuccess()) {
                    long now = System.currentTimeMillis();
                    long maxAge = cacheControl.maxAgeSeconds();
                    long softExpire = now + maxAge * 1000;
                    System.out.println(":" + (softExpire - now) / 1000 + "");
                    Cache.Entry entry = new Cache.Entry();
                    entry.softTtl = softExpire;
                    entry.ttl = entry.softTtl;
                    // entry.serverDate = serverDate;
                    // entry.responseHeaders = headers;
                    entry.mimeType = mimeType;
                    System.out.println("request.cacheControl()==" + request.cacheControl());
                    entry.data = string.getBytes(UTF8);
                    cache.put(request.urlString(), entry);
                }//from ww  w.  j av  a  2 s  .c  om
            }
        }
    }
}