Cache Service
Cache Service is a powerful Flutter package that provides widgets for efficient caching and displaying of images and PDFs. It utilizes advanced caching strategies like LRU (Least Recently Used) and Priority Queue to optimize resource usage and enhance the performance of your Flutter applications.
Features
- CachedImage Widget: Display images with built-in caching to reduce loading times and network requests.
- CachedPDF Widget: Display PDF files with caching support, ensuring fast loading and offline access.
- LRU Cache: Efficiently manages frequently accessed assets by automatically evicting the least-used items.
- Priority Queue: Prioritizes cached assets based on access frequency, ensuring the most relevant assets are always available.
- Customizable Cache Settings: Easily configure cache size, expiration policies, and more to fit your app's needs.
- Shimmer Effect Support: Provides a shimmer effect while loading assets, offering a smooth user experience.
Installation
Add the package to your pubspec.yaml
file:
dependencies:
cache_service: latest_version
Then, run:
flutter pub get
Usage
CachedImage Widget
The CachedImage
widget makes it easy to display and cache images from the internet.
import 'package:cache_service/cached_image.dart';
CachedImage(
url: 'https://example.com/image.jpg',
);
CachedPDF Widget
Use the CachedPDF
widget to display and cache PDF files, reducing load times and network usage.
import 'package:cache_service/cached_pdf.dart';
CachedPDF(
url: 'https://example.com/document.pdf',
);
Customizing Cache Behavior
You can customize the cache size, expiration policies, and more by configuring the package's settings. Below is an example of how to initialize the cache service with custom parameters:
import 'package:cache_service/cache_service.dart';
void main() {
CacheService.init(
);
runApp(MyApp());
}
Example
For a complete example, check out the example directory, which demonstrates how to use the CachedImage
and CachedPDF
widgets in a real-world scenario.
Contributing
Contributions are welcome! If you have any ideas, suggestions, or issues, feel free to open an issue or a pull request on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you find this package useful, please consider giving it a star on GitHub. Your support is appreciated!
Libraries
- cache_service
- Support for doing something awesome.