feat: Implement expiring cache for S3 image URLs, add error retry logic, and clear image caches on app startup.
This commit is contained in:
@@ -33,6 +33,7 @@ class _S3ImageState extends State<S3Image> {
|
||||
String? _resolvedUrl;
|
||||
bool _loading = true;
|
||||
bool _failed = false;
|
||||
bool _retried = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -106,13 +107,22 @@ class _S3ImageState extends State<S3Image> {
|
||||
|
||||
return CachedNetworkImage(
|
||||
imageUrl: _resolvedUrl!,
|
||||
cacheKey: widget.imageUrl,
|
||||
cacheKey: widget.imageUrl ?? _resolvedUrl!,
|
||||
width: widget.width,
|
||||
height: widget.height,
|
||||
fit: widget.fit,
|
||||
alignment: widget.alignment,
|
||||
placeholder: (ctx, _) => _buildPlaceholder(ctx),
|
||||
errorWidget: (ctx, _, _) => _buildError(ctx),
|
||||
errorWidget: (ctx, _, err) {
|
||||
// On error (expired URL), evict and retry once
|
||||
if (!_retried) {
|
||||
_retried = true;
|
||||
ImageUrlResolver.instance.evict(widget.imageUrl);
|
||||
_resolve();
|
||||
return _buildPlaceholder(ctx);
|
||||
}
|
||||
return _buildError(ctx);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user