A library caching solution with Time-to-Live (TTL) support, enabling efficient storage and retrieval of HTTP responses using the file system. Ideal for optimizing network performance and reducing redundant requests.
- ✅ Cache files locally with a specified TTL
- ✅ Uses Dio for efficient downloading
- ✅ Automatically clears expired cache
- ✅ Supports custom cache directories
Add this to your pubspec.yaml
:
dependencies:
dio_cache_ttl: ^0.3.3
Or add via CLI:
flutter pub add dio_cache_ttl
dependencies:
dio_cache_ttl:
git:
url: https://github.com/cas8938/dio_cache_ttl.git
import 'package:dio_cache_ttl/dio_cache_ttl.dart';
import 'dart:io';
import 'package:dio_cache_ttl/dio_cache_ttl.dart';
void main() async {
File file = await dioCache(
"https://example.com/sample.pdf",
extFile: "pdf",
ttl: Duration(hours: 1), // Cache for 1 hour
);
print("File saved at: ${file.path}");
}
Run tests using:
flutter test
This project is licensed under the MIT License - see the LICENSE file for details.