zeba_academy_offline_cache 1.0.0
zeba_academy_offline_cache: ^1.0.0 copied to clipboard
A lightweight and powerful offline caching solution for Flutter. Supports cache-first and network-first strategies with auto expiry, built for offline-first apps, e-commerce, and content platforms.
š¦ zeba_academy_offline_cache #
A lightweight, powerful, and flexible offline caching solution for Flutter apps.
Designed for offline-first applications, this package enables seamless data access even without internet connectivity.
⨠Features #
- ā” Cache network requests for offline use
- š Auto expiry & refresh mechanism
- šÆ Multiple cache policies (cache-first, network-first, etc.)
- š§© Supports JSON, images, and extendable for videos
- šŖ¶ Lightweight storage using Hive
- š Simple and clean API
š¦ Installation #
Add this to your pubspec.yaml:
dependencies:
zeba_academy_offline_cache: ^1.0.0
š Getting Started #
1. Initialize Storage #
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await StorageService.init();
runApp(MyApp());
}
2. Fetch Data with Cache #
final data = await CacheManager.fetch(
url: "https://jsonplaceholder.typicode.com/posts",
policy: CachePolicy.cacheFirst,
expiry: Duration(minutes: 10),
);
šÆ Cache Policies #
| Policy | Description |
|---|---|
| cacheFirst | Uses cache first, falls back to network |
| networkFirst | Uses network first, falls back to cache |
| cacheOnly | Only returns cached data |
| networkOnly | Always fetches from network |
š¦ Example #
final result = await CacheManager.fetch(
url: "https://api.example.com/data",
policy: CachePolicy.networkFirst,
);
print(result);
š§ Use Cases #
- š± Offline-first mobile apps
- š E-commerce apps
- š° Content/news apps
- š Learning platforms
āļø Advanced Usage #
Custom Expiry #
await CacheManager.fetch(
url: "https://api.example.com/data",
expiry: Duration(hours: 1),
);
Clear Cache #
await StorageService.clear();
š ļø Roadmap #
- š Background sync
- š” Connectivity-aware caching
- š¼ļø Advanced image & video caching
- š Secure storage (encryption)
š¤ Contributing #
Contributions are welcome! Feel free to open issues or submit pull requests.
š License #
This project is licensed under the GPL License.
šØāš» About Me #
⨠Iām Sufyan bin Uzayr, an open-source developer passionate about building and sharing meaningful projects. You can learn more about me and my work at sufyanism.com or connect with me on Linkedin
š Your all-in-one no-bloat hub! #
š Explore cutting-edge resources in coding, tech, and development at zeba.academy and code.zeba.academy. Empower yourself with practical skills through curated directives, real-world projects, and hands-on experience. Level up your tech game today! š»āØ
Zeba Academy is a learning platform dedicated to coding, technology, and development. ā” Visit our main site: zeba.academy ā” Explore hands-on courses and resources at: code.zeba.academy ā” Check out our YouTube for more tutorials: zeba.academy ā” Follow us on Instagram: zeba.academy
Thank you for visiting!