Building an Open Source Carefree Android Disk Cache
Article Summary
Instagram's disk cache was causing more crashes than any other component in their Android app. The culprit? A well-intentioned open source library that made error handling a developer nightmare.
Instagram's engineering team rebuilt their Android disk caching system from scratch after DiskLruCache's complex exception handling led to constant NPEs and IOExceptions. Engineer Jimmy Zhang shares how they designed IgDiskCache to be truly "carefree" for developers.
Key Takeaways
- DiskLruCache required NULL checks and manual IOException handling at every cache operation
- Cache related crashes topped Instagram's crash list for over a year
- IgDiskCache uses stub instances so developers never check for NULL
- The new cache handles IOExceptions internally and prevents UI thread blocking
- Dramatically reduced crashes after launch while simplifying code
Critical Insight
By rethinking cache design around the principle that caches can always say "I don't have this," Instagram eliminated their top crash category and made disk caching simple.