This Flutter project showcases efficient cache management techniques using Hive and Cached Network Image. It demonstrates handling API calls, caching responses, and managing image loading and caching.
This demo was developed as part of a presentation at a flutter meetup in Montreal for the Google Developer Group 🇨🇦🍁
- API data fetching and handling.
- Advanced caching of API responses using Hive.
- Image caching with Cached Network Image.
- Demonstration of cache management in gallery and weather screens.
- CacheEntry: Represents cached items with data and an expiration time. Includes a method to check if the cache is expired.
- CacheEntryAdapter: Handles serialization and deserialization of CacheEntry objects for Hive.
- CacheManager: Central manager for caching operations. It initializes Hive, manages Hive boxes for storing cached data, and handles storage, retrieval, and validity checks of cache entries.
- DataManager Classes: Manage feature-specific data (gallery and weather), interfacing with ApiClient for data fetching and CacheManager for caching.
Cached data's validity is controlled by an expiration time. System checks if cached data exists and is valid; if not, it fetches fresh data from the API and updates the cache with a new expiration time. expirationDurationInSeconds in data managers specifies the duration for which cached data remains valid.
To run this project:
- Clone the repository.
- Navigate to the project directory.
- Run
flutter pub get
to install dependencies. - Launch the app with
flutter run
.
- api/: API integration and data fetching logic.
- cache/: Caching mechanisms using Hive.
- data/: Data management for different features.
- screens/: UI components for gallery and weather displays.
- main.dart: Main entry point of the application.
- Hive
- Cached Network Image