Caching and Performance
Memory and disk caching basics.
Why Caching Matters
Downloading and decoding an image is expensive: it uses bandwidth, battery, and CPU. If you refetch the same image every time a list scrolls, your app feels slow and burns data.
Caching stores decoded images and downloaded bytes so the next request is nearly instant. Coil ships with two caches by default: an in-memory cache (fast, decoded bitmaps) and a disk cache (persistent, raw bytes).
This lesson explains how they work and how to tune them.
Two Layers: Memory and Disk
Coil checks caches in order:
- Memory cache: holds recently used decoded bitmaps in RAM. A hit here is instant, no decoding needed.
- Disk cache: stores the original downloaded bytes on the device. A hit here skips the network but still decodes.
- Network: the slow path, only used when both caches miss.
Memory is fast but small and cleared when the app dies; disk is larger and survives restarts.
All lessons in this course
- Loading Images with Coil
- Placeholders and Error States
- Caching and Performance
- Playing Audio and Video