Cache Manager implementation that integrates with Firebase Performance Monitoring to automatically record traces for network requests.
The Firebase Performance flutter plugin allows your app to record traces for network requests and publishes them to Firebase Performance Monitoring. However, the plugin does not automatically collect traces for all network requests your app makes.
One popular unsupported widget is cached_network_image
,
a flutter library to show images from the internet and keep them in the cache directory. Under the hood,
this widget uses flutter_cache_manager
to
download and cache files in the cache directory of the app. When a cache miss occurs, the network
request to download the file is not automatically traced with Firebase Performance flutter plugin.
This package (traced_cache_manager
) provides a custom Cache Manager implementation that automatically
traces network requests and publishes them to Firebase Performance Monitoring. It can be used with
cached_network_image
to automatically trace network
requests when downloading images from the internet.
- Add the Firebase Performance flutter plugin to your app. Follow the setup instructions in that package to integrate with Firebase Performance Monitoring.
- Install this package.
There are 3 use cases for this custom cache implementation.
Automatically trace all network requests made by the CachedNetworkImage
widget.
CachedNetworkImage(
imageUrl: 'https://picsum.photos/500',
...
cacheManager: TracedCacheManager(),
)
Automatically trace all network requests made when fetching files for the cache.
Future<File> fetchFile(String uri) async {
return await TracedCacheManager().getSingleFile(uri);
}
If you are writing a custom cache implementation and want automatic tracing of network requests,
you can use TracedHttpFileService
as an argument to the BaseCacheManager
.
class MyCustomCacheManager extends BaseCacheManager {
...
MyCustomCacheManager({...}) : super(key, fileService: TracedHttpFileService(), ...);
}
If you have an issue with this library, file an issue.
If you do not see traces in the Firebase Console, reference the official Firebase Troubleshooting Guide. Note that it may take 24-48 hours for network traces to show up.
Consider clearing your application's cache to force network requests on a cache miss.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.