use of com.android.volley.Cache in project FastDev4Android by jiangqqlmj.
the class HttpHeaderParserTest method parseCaseInsensitive.
@Test
public void parseCaseInsensitive() {
long now = System.currentTimeMillis();
Header[] headersArray = new Header[5];
headersArray[0] = new BasicHeader("eTAG", "Yow!");
headersArray[1] = new BasicHeader("DATE", rfc1123Date(now));
headersArray[2] = new BasicHeader("expires", rfc1123Date(now + ONE_HOUR_MILLIS));
headersArray[3] = new BasicHeader("cache-control", "public, max-age=86400");
headersArray[4] = new BasicHeader("content-type", "text/plain");
Map<String, String> headers = BasicNetwork.convertHeaders(headersArray);
NetworkResponse response = new NetworkResponse(0, null, headers, false);
Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
assertNotNull(entry);
assertEquals("Yow!", entry.etag);
assertEqualsWithin(now + ONE_DAY_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
assertEquals(entry.softTtl, entry.ttl);
assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
}
use of com.android.volley.Cache in project FastDev4Android by jiangqqlmj.
the class CacheTestUtils method makeRandomCacheEntry.
/**
* Makes a random cache entry.
* @param data Data to use, or null to use random data
* @param isExpired Whether the TTLs should be set such that this entry is expired
* @param needsRefresh Whether the TTLs should be set such that this entry needs refresh
*/
public static Cache.Entry makeRandomCacheEntry(byte[] data, boolean isExpired, boolean needsRefresh) {
Random random = new Random();
Cache.Entry entry = new Cache.Entry();
if (data != null) {
entry.data = data;
} else {
entry.data = new byte[random.nextInt(1024)];
}
entry.etag = String.valueOf(random.nextLong());
entry.lastModified = random.nextLong();
entry.ttl = isExpired ? 0 : Long.MAX_VALUE;
entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE;
return entry;
}
use of com.android.volley.Cache in project android-volley by mcxiaoke.
the class CacheTestUtils method makeRandomCacheEntry.
/**
* Makes a random cache entry.
* @param data Data to use, or null to use random data
* @param isExpired Whether the TTLs should be set such that this entry is expired
* @param needsRefresh Whether the TTLs should be set such that this entry needs refresh
*/
public static Cache.Entry makeRandomCacheEntry(byte[] data, boolean isExpired, boolean needsRefresh) {
Random random = new Random();
Cache.Entry entry = new Cache.Entry();
if (data != null) {
entry.data = data;
} else {
entry.data = new byte[random.nextInt(1024)];
}
entry.etag = String.valueOf(random.nextLong());
entry.lastModified = random.nextLong();
entry.ttl = isExpired ? 0 : Long.MAX_VALUE;
entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE;
return entry;
}
use of com.android.volley.Cache in project iosched by google.
the class CacheTestUtils method makeRandomCacheEntry.
/**
* Makes a random cache entry.
* @param data Data to use, or null to use random data
* @param isExpired Whether the TTLs should be set such that this entry is expired
* @param needsRefresh Whether the TTLs should be set such that this entry needs refresh
*/
public static Cache.Entry makeRandomCacheEntry(byte[] data, boolean isExpired, boolean needsRefresh) {
Random random = new Random();
Cache.Entry entry = new Cache.Entry();
if (data != null) {
entry.data = data;
} else {
entry.data = new byte[random.nextInt(1024)];
}
entry.etag = String.valueOf(random.nextLong());
entry.serverDate = random.nextLong();
entry.ttl = isExpired ? 0 : Long.MAX_VALUE;
entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE;
return entry;
}
use of com.android.volley.Cache in project android_frameworks_base by AOSPA.
the class URLFetcher method getExpirationTimeMillisFromHTTPHeader.
/**
* Parses the HTTP headers to compute the ttl.
*
* @param headers a map that map the header key to the header values. Can be null.
* @return the ttl in millisecond or null if the ttl is not specified in the header.
*/
private Long getExpirationTimeMillisFromHTTPHeader(Map<String, List<String>> headers) {
if (headers == null) {
return null;
}
Map<String, String> joinedHeaders = joinHttpHeaders(headers);
NetworkResponse response = new NetworkResponse(null, joinedHeaders);
Cache.Entry cachePolicy = HttpHeaderParser.parseCacheHeaders(response);
if (cachePolicy == null) {
// Cache is disabled, set the expire time to 0.
return DO_NOT_CACHE_RESULT;
} else if (cachePolicy.ttl == 0) {
// Cache policy is not specified, set the expire time to 0.
return DO_NOT_CACHE_RESULT;
} else {
// cachePolicy.ttl is actually the expire timestamp in millisecond.
return cachePolicy.ttl;
}
}
Aggregations