Example usage for com.squareup.okhttp CacheControl maxAgeSeconds

List of usage examples for com.squareup.okhttp CacheControl maxAgeSeconds

Introduction

In this page you can find the example usage for com.squareup.okhttp CacheControl maxAgeSeconds.

Prototype

int maxAgeSeconds

To view the source code for com.squareup.okhttp CacheControl maxAgeSeconds.

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);
                }//ww w .  j a  v a 2s . c  om
            }
        }
    }
}