Lesson 7 of 9
Image Caching with expo-image
Every image in a feed is fetched from the network. Without caching, scrolling up re-downloads images already seen. expo-image provides a shared disk cache that persists between app sessions.
expo-image Cache Policy
import { Image } from 'expo-image';
// cachePolicy controls how images are cached:
// 'memory-disk' (default) - LRU memory cache + disk cache (best for feeds)
// 'disk' - disk only (saves RAM for large images)
// 'memory' - memory only (never persists across sessions)
// 'none' - always fetch from network (for real-time content like security cameras)
function FeedImage({ uri }: { uri: string }) {
return (
<Image
source={{ uri }}
cachePolicy="memory-disk" // cached across sessions
contentFit="cover"
transition={{ duration: 200, effect: 'cross-dissolve' }}
recyclingKey={uri} // hint to reuse cell in FlatList
style={{ width: '100%', aspectRatio: 16 / 9 }}
accessibilityLabel="Feed image"
/>
);
}
// Prefetch images before they scroll into view
import { Image as ExpoImage } from 'expo-image';
async function prefetchImages(uris: string[]) {
await Promise.all(uris.map(uri => ExpoImage.prefetch(uri)));
}
// Call before the user reaches those items in the list
function onScrollNearEnd(nextBatchUris: string[]) {
prefetchImages(nextBatchUris);
}Tip
Tip
Practice Image Caching with expoimage in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Next-generation image caching with blurhash placeholders and native Glide/SDWebImage
Practice Task
Note
Practice Task - (1) Write a working example of Image Caching with expoimage from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Image Caching with expoimage is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Finished this lesson?