當前位置: 首頁>>代碼示例>>Java>>正文


Java Cache.Entry方法代碼示例

本文整理匯總了Java中com.android.volley.Cache.Entry方法的典型用法代碼示例。如果您正苦於以下問題:Java Cache.Entry方法的具體用法?Java Cache.Entry怎麽用?Java Cache.Entry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.android.volley.Cache的用法示例。


在下文中一共展示了Cache.Entry方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeRandomCacheEntry

import com.android.volley.Cache; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:Ace201m,項目名稱:Codeforces,代碼行數:22,代碼來源:CacheTestUtils.java

示例2: cacheHeaderSerialization

import com.android.volley.Cache; //導入方法依賴的package包/類
@Test public void cacheHeaderSerialization() throws Exception {
    Cache.Entry e = new Cache.Entry();
    e.data = new byte[8];
    e.serverDate = 1234567L;
    e.lastModified = 13572468L;
    e.ttl = 9876543L;
    e.softTtl = 8765432L;
    e.etag = "etag";
    e.responseHeaders = new HashMap<String, String>();
    e.responseHeaders.put("fruit", "banana");

    CacheHeader first = new CacheHeader("my-magical-key", e);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    first.writeHeader(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    CacheHeader second = CacheHeader.readHeader(bais);

    assertEquals(first.key, second.key);
    assertEquals(first.serverDate, second.serverDate);
    assertEquals(first.lastModified, second.lastModified);
    assertEquals(first.ttl, second.ttl);
    assertEquals(first.softTtl, second.softTtl);
    assertEquals(first.etag, second.etag);
    assertEquals(first.responseHeaders, second.responseHeaders);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:DiskBasedCacheTest.java

示例3: parseCacheHeaders_cacheControlMustRevalidateWithMaxAgeAndStale

import com.android.volley.Cache; //導入方法依賴的package包/類
@Test public void parseCacheHeaders_cacheControlMustRevalidateWithMaxAgeAndStale() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));

    // - max-age (entry.softTtl) indicates that the asset is fresh for 1 day
    // - stale-while-revalidate (entry.ttl) indicates that the asset may
    // continue to be served stale for up to additional 7 days, but this is
    // ignored in this case because of the must-revalidate header.
    headers.put("Cache-Control",
            "must-revalidate, max-age=86400, stale-while-revalidate=604800");

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(now + ONE_DAY_MILLIS, entry.softTtl, ONE_MINUTE_MILLIS);
    assertEquals(entry.softTtl, entry.ttl);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:HttpHeaderParserTest.java

示例4: setUp

import com.android.volley.Cache; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    url = "http://neopixl.com/";

    headers.put("If-Range", "Wed, 21 Oct 2017 07:28:00 GMT");
    headers.put("X-ApiKey", "azerty");
    headers.put("Authorization", "Bearer 1000:2b52d2ccfd6007d7a8d58d8cabb32bc0");

    dummyData = new RequestData("neopixl.jpg", new byte[16]);

    byte[] data = new byte[16];
    Cache.Entry cacheEntry = CacheTestUtils.makeRandomCacheEntry(data);
    mDelivery = new ImmediateResponseDelivery();
    mSuccessResponse = Response.success(dummyResponse, cacheEntry);
    volleyError = new ServerError();
    mErrorResponse = Response.error(volleyError);
}
 
開發者ID:neopixl,項目名稱:Spitfire,代碼行數:20,代碼來源:UploadRequestTest.java

示例5: parseCacheHeaders_normalExpire

import com.android.volley.Cache; //導入方法依賴的package包/類
@Test public void parseCacheHeaders_normalExpire() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Last-Modified", rfc1123Date(now - ONE_DAY_MILLIS));
    headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);

    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(entry.serverDate, now, ONE_MINUTE_MILLIS);
    assertEqualsWithin(entry.lastModified, (now - ONE_DAY_MILLIS), ONE_MINUTE_MILLIS);
    assertTrue(entry.softTtl >= (now + ONE_HOUR_MILLIS));
    assertTrue(entry.ttl == entry.softTtl);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:HttpHeaderParserTest.java

示例6: parseCacheHeaders_expiresInPast

import com.android.volley.Cache; //導入方法依賴的package包/類
@Test public void parseCacheHeaders_expiresInPast() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Expires", rfc1123Date(now - ONE_HOUR_MILLIS));

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);

    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(entry.serverDate, now, ONE_MINUTE_MILLIS);
    assertEquals(0, entry.ttl);
    assertEquals(0, entry.softTtl);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:HttpHeaderParserTest.java

示例7: parseCacheHeaders_cacheControlOverridesExpires

import com.android.volley.Cache; //導入方法依賴的package包/類
@Test public void parseCacheHeaders_cacheControlOverridesExpires() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
    headers.put("Cache-Control", "public, max-age=86400");

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);

    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(now + ONE_DAY_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
    assertEquals(entry.softTtl, entry.ttl);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:HttpHeaderParserTest.java

示例8: addCacheHeaders

import com.android.volley.Cache; //導入方法依賴的package包/類
private void addCacheHeaders(Map<String, String> headers, Cache.Entry entry) {
  // If there's no cache entry, we're done.
  if (entry == null) {
    return;
  }

  if (entry.etag != null) {
    headers.put("If-None-Match", entry.etag);
  }

  if (entry.serverDate > 0) {
    Date refTime = new Date(entry.serverDate);
    headers.put("If-Modified-Since", DateUtils.formatDate(refTime));
  }
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:16,代碼來源:DrBasicNetwork.java

示例9: parseCacheHeaders_cacheControlMustRevalidateNoMaxAge

import com.android.volley.Cache; //導入方法依賴的package包/類
@Test public void parseCacheHeaders_cacheControlMustRevalidateNoMaxAge() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
    headers.put("Cache-Control", "must-revalidate");

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(now, entry.ttl, ONE_MINUTE_MILLIS);
    assertEquals(entry.softTtl, entry.ttl);
}
 
開發者ID:Ace201m,項目名稱:Codeforces,代碼行數:13,代碼來源:HttpHeaderParserTest.java

示例10: testParseCacheHeaders_serverRelative

import com.android.volley.Cache; //導入方法依賴的package包/類
public void testParseCacheHeaders_serverRelative() {

        long now = System.currentTimeMillis();
        // Set "current" date as one hour in the future
        headers.put("Date", rfc1123Date(now + ONE_HOUR_MILLIS));
        // TTL four hours in the future, so should be three hours from now
        headers.put("Expires", rfc1123Date(now + 4 * ONE_HOUR_MILLIS));

        Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);

        assertEqualsWithin(now + 3 * ONE_HOUR_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
        assertEquals(entry.softTtl, entry.ttl);
    }
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:14,代碼來源:HttpHeaderParserTest.java

示例11: testParseCacheHeaders_cacheControlOverridesExpires

import com.android.volley.Cache; //導入方法依賴的package包/類
public void testParseCacheHeaders_cacheControlOverridesExpires() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
    headers.put("Cache-Control", "public, max-age=86400");

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);

    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(now + 24 * ONE_HOUR_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
    assertEquals(entry.softTtl, entry.ttl);
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:14,代碼來源:HttpHeaderParserTest.java

示例12: testParseCacheHeaders_expiresInPast

import com.android.volley.Cache; //導入方法依賴的package包/類
public void testParseCacheHeaders_expiresInPast() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Expires", rfc1123Date(now - ONE_HOUR_MILLIS));

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);

    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(entry.serverDate, now, ONE_MINUTE_MILLIS);
    assertEquals(0, entry.ttl);
    assertEquals(0, entry.softTtl);
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:14,代碼來源:HttpHeaderParserTest.java

示例13: parseCacheHeaders_cacheControlMustRevalidateWithMaxAge

import com.android.volley.Cache; //導入方法依賴的package包/類
@Test public void parseCacheHeaders_cacheControlMustRevalidateWithMaxAge() {
    long now = System.currentTimeMillis();
    headers.put("Date", rfc1123Date(now));
    headers.put("Expires", rfc1123Date(now + ONE_HOUR_MILLIS));
    headers.put("Cache-Control", "must-revalidate, max-age=3600");

    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
    assertNotNull(entry);
    assertNull(entry.etag);
    assertEqualsWithin(now + ONE_HOUR_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
    assertEquals(entry.softTtl, entry.ttl);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:HttpHeaderParserTest.java

示例14: makeRandomCacheEntry

import com.android.volley.Cache; //導入方法依賴的package包/類
/**
 * Like {@link #makeRandomCacheEntry(byte[], boolean, boolean)} but
 * defaults to an unexpired entry.
 */
public static Cache.Entry makeRandomCacheEntry(byte[] data) {
    return makeRandomCacheEntry(data, false, false);
}
 
開發者ID:neopixl,項目名稱:Spitfire,代碼行數:8,代碼來源:CacheTestUtils.java


注:本文中的com.android.volley.Cache.Entry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。