Implementing Image Caching in Mobile Application
Images are one of the main reasons for visible lags in mobile apps. Feed scroll with avatars stutters not because device is weak, but because JPEG decoding happens on main thread when cell should already display. Proper caching solves this, but "just add Glide" and "properly configure caching" are different tasks.
Standard Solutions and Their Limits
Android: Glide and Coil — most common libraries. Glide with default settings caches in two levels: memory cache (LruCache with size derived from available memory) and disk cache (DiskLruCache). Coil written on Kotlin Coroutines and better integrates with Compose via AsyncImage. Problem arises when network image size doesn't match ImageView size: Glide by default caches already-transformed image (for specific view size), causing cache misses at different sizes of same URL.
iOS: NSCache + manual logic or Kingfisher and SDWebImage libraries. Kingfisher is de-facto standard for SwiftUI via .setImage(with:). Common problem: cache doesn't account for Cache-Control headers, and stale images show to user until TTL expires manually.
React Native: react-native-fast-image over Glide/SDWebImage. Standard Image in RN has no proper disk-cache — pictures reload on every component mount, noticeable when navigating between screens.
What We Actually Configure
Multi-level cache: L1 in memory (fast, small — 20-30 MB), L2 on disk (slower, big — 200-500 MB). Sizes chosen by content type: in news app with many unique images, disk cache matters more; in messenger with avatars, memory cache.
Placeholder and error-state separately. Showing blank while loading is worse than showing skeleton. Error state should be explicit but not break layout.
Prefetch (prefetch) for lists: load next N images before user scrolls to them. In RecyclerView — via RecyclerView.RecycledViewPool + DiffUtil. In UITableView — via prefetchDataSource (available since iOS 10).
Cache invalidation: URL with version (/avatar.jpg?v=42) or ETag. Without invalidation strategy, users see stale avatars after profile photo change.
Timeline: two to four business days depending on platform and content complexity.







