dio_cache_ttl 0.3.1
dio_cache_ttl: ^0.3.1 copied to clipboard
Caching system for Flutter using dio with TTL.
dio_cache_ttl #
A Flutter package for caching files using Dio with Time-to-Live (TTL) support.
Features #
- Cache files locally with a specified TTL.
- Uses
Dio
for downloading. - Automatically clears expired cache.
- Supports custom cache directories.
Installation #
Add this to your pubspec.yaml
:
dependencies:
dio_cache_ttl:
git:
url: https://github.com/cas8938/dio_cache_ttl.git
Or add via CLI:
flutter pub add dio_cache_ttl
Usage #
Import the package #
import 'package:dio_cache_ttl/dio_cache_ttl.dart';
Cache a file #
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}");
}
Testing #
Run tests using:
flutter test
License #
This project is licensed under the MIT License - see the LICENSE file for details.