feat: Implement expiring cache for S3 image URLs, add error retry logic, and clear image caches on app startup.

This commit is contained in:
pradeepkumar
2026-03-19 10:54:49 +05:30
parent 2494bdc868
commit 62a4a26e9a
3 changed files with 34 additions and 7 deletions

View File

@@ -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);
},
);
}
}