How echowaves/expo-cached-image works
Project type and purpose
• This is an open-source React Native component library (expo-cached-image) built for Expo apps.
• Its purpose is to provide a drop-in <CachedImage> component that transparently handles remote image downloading, local caching, cache expiration, cleanup, and secure key sanitization.
File structure
• Top-level files: package.json, Babel and Metro configs, ESLint, TypeScript config → a published npm package.
• src/
• consts.ts → likely holds constants (e.g. default cache paths, expiration values).
• index.tsx → entry point exporting the <CachedImage> component and the CacheManager API.
• No “frontend” or “backend” directories—instead a single library module.
README for additional insights
• Describes two main APIs:
a) The <CachedImage> React component (props: source, cacheKey, placeholderContent, etc.)
b) The static CacheManager (methods: addToCache, getCachedUri, downloadAsync, getMetadata).
• Mentions Expo FileSystem under the hood for disk storage, network calls with optional headers, key sanitization for security.
a. Main components
• Consumer App (your screen or UI layer)
• CachedImage Component
• CacheManager Module
• Expo FileSystem (local disk storage)
• Network / HTTP Server (image host)
• Optional: React Native’s Image component (for actual rendering)
b. Relationships and interactions
1. Consumer renders <CachedImage> → passes uri + cacheKey
2. <CachedImage> invokes CacheManager.getCachedUri(key)
• If cache hit: read file from local FS → pass local uri to RN Image
• If miss or expired: call CacheManager.downloadAsync(uri, key, headers) → network request → write to FS → return local uri
3. While waiting: <CachedImage> displays placeholderContent
4. CacheManager.getMetadata and cleanup routines run periodically or on demand
c. Architectural patterns & principles
• Single responsibility: <CachedImage> handles UI; CacheManager handles persistence + networking.
• Abstraction of platform APIs (Expo FileSystem) behind CacheManager.
• Secure key handling (sanitization before FS interaction).
• Asynchronous I/O / Promise-based flows.
d. Key technologies
• React Native / Expo
• TypeScript
• Expo FileSystem API
• React Native Image component
• Standard Node/npm packaging