JakeWharton / DiskLruCache

Java implementation of a Disk-based LRU cache which specifically targets Android compatibility.
http://jakewharton.github.io/DiskLruCache
Apache License 2.0
5.79k stars 1.18k forks source link

Serializing an ArrayList works in a JUnit test, but not in other methods #51

Closed elliottsj closed 10 years ago

elliottsj commented 10 years ago

See https://gist.github.com/elliottsj/8198330

The JUnit test runs fine and creates the file DiskLruCacheTest/test-store-array-list.0, but when the same code is put into the main method, the program hangs for a while and does not create the file DiskLruCache/test-store-array-list.0.

I'm using JDK 1.7.0_40 in the gist, but I'm having the same issue in my Android app (API 19) where ArrayLists are not being written to the cache.

JakeWharton commented 10 years ago

Haven't figured out the problem yet, but 20 ^ 2 is 22, not 400. ^ is exclusive OR. That shouldn't be causing your problems, though.

elliottsj commented 10 years ago

Thanks; it looks like the cache size was the issue. 20 * 2^20 == 60, while it should have been 20 * Math.pow(2, 20) == 20971520. I've updated the gist with the corrected cache size.