本文整理匯總了Java中com.android.volley.toolbox.HttpHeaderParser.parseDateAsEpoch方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpHeaderParser.parseDateAsEpoch方法的具體用法?Java HttpHeaderParser.parseDateAsEpoch怎麽用?Java HttpHeaderParser.parseDateAsEpoch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.android.volley.toolbox.HttpHeaderParser
的用法示例。
在下文中一共展示了HttpHeaderParser.parseDateAsEpoch方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cache
import com.android.volley.toolbox.HttpHeaderParser; //導入方法依賴的package包/類
/**
* 強製緩存
* @param response 接收體
* @param maxAge 緩存時間
*/
private static Cache.Entry cache(NetworkResponse response, long maxAge) {
long now = System.currentTimeMillis();
if (maxAge == 0)
maxAge = 60;
Map<String, String> headers = response.headers;
long serverDate = 0;
long softExpire = 0;
String serverEtag = null;
String headerValue;
headerValue = headers.get("Date");
if (headerValue != null) {
serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
softExpire = now + maxAge * 1000;
Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
entry.ttl = entry.softTtl;
entry.serverDate = serverDate;
entry.responseHeaders = headers;
return entry;
}
示例2: cache
import com.android.volley.toolbox.HttpHeaderParser; //導入方法依賴的package包/類
/***
* 緩存的數據
*
* @param response
* @param maxAge 緩存的有效時間,默認60秒
* @param oldSoftExpire
* @return
*/
private Cache.Entry cache(NetworkResponse response, long maxAge, long oldSoftExpire) {
long now = System.currentTimeMillis();
if (maxAge == 0) maxAge = CACHE_MAXAGE;
// (如果判斷服務器是用的緩存的,還是從網絡上獲取的呢,當前時間與之前記錄的時間對比?如果大於60秒則表示是新的麽?可以有)
long softExpire = now + maxAge * 1000;
Log.e("", "wenjun request cache() oldSoftExpire - now = " + (oldSoftExpire - now) + ", oldSoftExpire = " + oldSoftExpire + ", softExpire = " + softExpire);
if ((oldSoftExpire > now) && (oldSoftExpire < softExpire)) {
//如果之前的時間一定大於現在的時間,並且之前的時間減去現在的時間如果在60秒內,則表示是同一個,不用再更新緩存了
return null;
}
Map<String, String> headers = response.headers;
long serverDate = 0;
String serverEtag = null;
String headerValue;
headerValue = headers.get("Date");
if (headerValue != null) {
serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
entry.ttl = entry.softTtl;
entry.serverDate = serverDate;
entry.responseHeaders = headers;
return entry;
}
示例3: parseIgnoreCacheHeaders
import com.android.volley.toolbox.HttpHeaderParser; //導入方法依賴的package包/類
/**
* Extracts a {@link com.android.volley.Cache.Entry} from a {@link com.android.volley.NetworkResponse}.
* Cache-control headers are ignored. SoftTtl == 3 mins, ttl == 24 hours.
* @param response The network response to parse headers from
* @return a cache entry for the given response, or null if the response is not cacheable.
*/
public static Cache.Entry parseIgnoreCacheHeaders(NetworkResponse response) {
long now = System.currentTimeMillis();
Map<String, String> headers = response.headers;
long serverDate = 0;
String serverEtag;
String headerValue;
headerValue = headers.get("Date");
if (headerValue != null) {
serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
serverEtag = headers.get("ETag");
final long cacheHitButRefreshed = 3 * 60 * 1000; // in 3 minutes cache will be hit, but also refreshed on background
final long cacheExpired = 24 * 60 * 60 * 1000; // in 24 hours this cache entry expires completely
final long softExpire = now + cacheHitButRefreshed;
final long ttl = now + cacheExpired;
Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
entry.ttl = ttl;
entry.serverDate = serverDate;
entry.responseHeaders = headers;
return entry;
}
示例4: parseIgnoreCacheHeaders
import com.android.volley.toolbox.HttpHeaderParser; //導入方法依賴的package包/類
/**
* Extracts a {@link Cache.Entry} from a {@link NetworkResponse}.
* Cache-control headers are ignored. SoftTtl == 3 mins, ttl == 24 hours.
* @param response The network response to parse headers from
* @return a cache entry for the given response, or null if the response is not cacheable.
*/
public static Cache.Entry parseIgnoreCacheHeaders(NetworkResponse response) {
long now = System.currentTimeMillis();
Map<String, String> headers = response.headers;
long serverDate = 0;
String serverEtag = null;
String headerValue;
headerValue = headers.get("Date");
if (headerValue != null) {
serverDate = HttpHeaderParser.parseDateAsEpoch(headerValue);
}
serverEtag = headers.get("ETag");
final long cacheHitButRefreshed = 1 * 60 * 1000; // in 1 minutes cache will be hit, but also refreshed on background
final long cacheExpired = 24 * 60 * 60 * 1000; // in 24 hours this cache entry expires completely
final long softExpire = now + cacheHitButRefreshed;
final long ttl = now + cacheExpired;
Cache.Entry entry = new Cache.Entry();
entry.data = response.data;
entry.etag = serverEtag;
entry.softTtl = softExpire;
entry.ttl = ttl;
entry.serverDate = serverDate;
entry.responseHeaders = headers;
return entry;
}