diff options
author | Ficus Kirkpatrick <ficus@android.com> | 2015-03-08 23:53:05 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-03-08 23:53:05 +0000 |
commit | dbc6d33edd721b6d7d8b40eedd26e3d0f54d0193 (patch) | |
tree | fc18f03943e0ac3c90d2cf44070ebb0f65334447 | |
parent | 79d00f42dd34d409cd3b2deb0a82e99a0417e340 (diff) | |
parent | f42d384cece1686c75c282e5cb72fa9b340af5fe (diff) | |
download | volley-dbc6d33edd721b6d7d8b40eedd26e3d0f54d0193.tar.gz |
Merge "Fix broken DiskBasedCache"
-rw-r--r-- | src/main/java/com/android/volley/toolbox/DiskBasedCache.java | 11 | ||||
-rw-r--r-- | src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java | 39 |
2 files changed, 3 insertions, 47 deletions
diff --git a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java index 036b55a..ff687d6 100644 --- a/src/main/java/com/android/volley/toolbox/DiskBasedCache.java +++ b/src/main/java/com/android/volley/toolbox/DiskBasedCache.java @@ -62,7 +62,7 @@ public class DiskBasedCache implements Cache { private static final float HYSTERESIS_FACTOR = 0.9f; /** Magic number for current version of cache file format. */ - private static final int CACHE_MAGIC = 0x20140623; + private static final int CACHE_MAGIC = 0x20150306; /** * Constructs an instance of the DiskBasedCache at the specified directory. @@ -397,16 +397,11 @@ public class DiskBasedCache implements Cache { entry.etag = null; } entry.serverDate = readLong(is); + entry.lastModified = readLong(is); entry.ttl = readLong(is); entry.softTtl = readLong(is); entry.responseHeaders = readStringStringMap(is); - try { - entry.lastModified = readLong(is); - } catch (EOFException e) { - // the old cache entry format doesn't know lastModified - } - return entry; } @@ -435,10 +430,10 @@ public class DiskBasedCache implements Cache { writeString(os, key); writeString(os, etag == null ? "" : etag); writeLong(os, serverDate); + writeLong(os, lastModified); writeLong(os, ttl); writeLong(os, softTtl); writeStringStringMap(responseHeaders, os); - writeLong(os, lastModified); os.flush(); return true; } catch (IOException e) { diff --git a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java index bf1d258..0a8be77 100644 --- a/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java +++ b/src/test/java/com/android/volley/toolbox/DiskBasedCacheTest.java @@ -125,45 +125,6 @@ public class DiskBasedCacheTest { assertEquals(DiskBasedCache.readStringStringMap(bais), emptyValue); } - /** deserializing the old format into the new one. */ - @Test public void testCacheHeaderSerializationOldToNewFormat() throws Exception { - - final int CACHE_MAGIC = 0x20140623; - final String key = "key"; - final String etag = "etag"; - final long serverDate = 1234567890l; - final long ttl = 1357924680l; - final long softTtl = 2468013579l; - - Map<String, String> responseHeaders = new HashMap<String, String>(); - responseHeaders.put("first", "thing"); - responseHeaders.put("second", "item"); - - // write old sytle header (without lastModified) - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DiskBasedCache.writeInt(baos, CACHE_MAGIC); - DiskBasedCache.writeString(baos, key); - DiskBasedCache.writeString(baos, etag == null ? "" : etag); - DiskBasedCache.writeLong(baos, serverDate); - DiskBasedCache.writeLong(baos, ttl); - DiskBasedCache.writeLong(baos, softTtl); - DiskBasedCache.writeStringStringMap(responseHeaders, baos); - - // read / test new style header (with lastModified) - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - CacheHeader cacheHeader = CacheHeader.readHeader(bais); - - assertEquals(cacheHeader.key, key); - assertEquals(cacheHeader.etag, etag); - assertEquals(cacheHeader.serverDate, serverDate); - assertEquals(cacheHeader.ttl, ttl); - assertEquals(cacheHeader.softTtl, softTtl); - assertEquals(cacheHeader.responseHeaders, responseHeaders); - - // the old format doesn't know lastModified - assertEquals(cacheHeader.lastModified, 0); - } - @Test public void publicMethods() throws Exception { // Catch-all test to find API-breaking changes. |