diff options
author | Fabian Frank <fabian.frank.de@gmail.com> | 2014-08-09 12:05:26 -0700 |
---|---|---|
committer | Fabian Frank <fabian.frank.de@gmail.com> | 2014-08-11 14:47:18 -0700 |
commit | aab3ca2670c2a9ad888085ce8f1b34c6c9fc50a3 (patch) | |
tree | faa0cc2f299f1cc8c229c5c18af1ed81eb32ee6c /src | |
parent | 0e406003b5d434d8f16d7d6ad97d446060b788e6 (diff) | |
download | volley-aab3ca2670c2a9ad888085ce8f1b34c6c9fc50a3.tar.gz |
Improve DiskBasedCache initial scan performance
Using a BufferedInputStream significantly reduces the time it takes
to initialize the cache. On my Nexus 5 with ~330 files in cache init
time went from ~2s to ~0.5s with this change.
Change-Id: I3dd909e3235583306ff5943f69e3947a275bf968
Signed-off-by: Fabian Frank <fabian.frank.de@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/volley/toolbox/DiskBasedCache.java | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/com/android/volley/toolbox/DiskBasedCache.java b/src/com/android/volley/toolbox/DiskBasedCache.java index d397aad..b283788 100644 --- a/src/com/android/volley/toolbox/DiskBasedCache.java +++ b/src/com/android/volley/toolbox/DiskBasedCache.java @@ -21,6 +21,7 @@ import android.os.SystemClock; import com.android.volley.Cache; import com.android.volley.VolleyLog; +import java.io.BufferedInputStream; import java.io.EOFException; import java.io.File; import java.io.FileInputStream; @@ -149,9 +150,9 @@ public class DiskBasedCache implements Cache { return; } for (File file : files) { - FileInputStream fis = null; + BufferedInputStream fis = null; try { - fis = new FileInputStream(file); + fis = new BufferedInputStream(new FileInputStream(file)); CacheHeader entry = CacheHeader.readHeader(fis); entry.size = file.length(); putEntry(entry.key, entry); |