@@ -381,15 +381,86 @@ class ImageState extends EWidgetState<EnsembleImage> {
381381 }
382382 return fallbackWidget;
383383 }
384+
385+ }
386+
387+ /// Configuration for image caching behavior.
388+ /// Can be set at app level via theme.yaml:
389+ /// ```yaml
390+ /// App:
391+ /// imageCache:
392+ /// stalePeriodMinutes: 10080 # 7 days
393+ /// maxObjects: 500
394+ /// ```
395+ class ImageCacheConfig {
396+ static final ImageCacheConfig _instance = ImageCacheConfig ._internal ();
397+
398+ factory ImageCacheConfig () => _instance;
399+
400+ ImageCacheConfig ._internal ();
401+
402+ // Default values - 15 minutes stale period, 50 objects max
403+ static const int defaultStalePeriodMinutes = 15 ;
404+ static const int defaultMaxObjects = 50 ;
405+
406+ int _stalePeriodMinutes = defaultStalePeriodMinutes;
407+ int _maxObjects = defaultMaxObjects;
408+ bool _initialized = false ;
409+
410+ /// Gets the configured stale period in minutes
411+ int get stalePeriodMinutes => _stalePeriodMinutes;
412+
413+ /// Gets the configured max number of cached objects
414+ int get maxObjects => _maxObjects;
415+
416+ /// Whether the cache config has been explicitly initialized
417+ bool get isInitialized => _initialized;
418+
419+ /// Configure the image cache settings.
420+ /// Called from theme loader when parsing App.imageCache settings.
421+ void configure ({int ? stalePeriodMinutes, int ? maxObjects}) {
422+ if (stalePeriodMinutes != null && stalePeriodMinutes > 0 ) {
423+ _stalePeriodMinutes = stalePeriodMinutes;
424+ }
425+ if (maxObjects != null && maxObjects > 0 ) {
426+ _maxObjects = maxObjects;
427+ }
428+ _initialized = true ;
429+
430+ // Reinitialize the cache manager with new settings
431+ EnsembleImageCacheManager ._reinitialize ();
432+ }
433+
434+ /// Reset to default values (useful for testing)
435+ void reset () {
436+ _stalePeriodMinutes = defaultStalePeriodMinutes;
437+ _maxObjects = defaultMaxObjects;
438+ _initialized = false ;
439+ EnsembleImageCacheManager ._reinitialize ();
440+ }
384441}
385442
386443class EnsembleImageCacheManager {
387444 static const key = 'ensembleImageCacheKey' ;
388- static CacheManager instance = CacheManager (Config (
389- key,
390- stalePeriod: const Duration (minutes: 15 ),
391- maxNrOfCacheObjects: 50 ,
392- ));
445+
446+ static CacheManager _instance = _createCacheManager ();
447+
448+ static CacheManager get instance => _instance;
449+
450+ static CacheManager _createCacheManager () {
451+ final config = ImageCacheConfig ();
452+ return CacheManager (Config (
453+ key,
454+ stalePeriod: Duration (minutes: config.stalePeriodMinutes),
455+ maxNrOfCacheObjects: config.maxObjects,
456+ ));
457+ }
458+
459+ /// Reinitialize the cache manager with current config settings.
460+ /// Called when ImageCacheConfig.configure() is called.
461+ static void _reinitialize () {
462+ _instance = _createCacheManager ();
463+ }
393464}
394465
395466class PinchToZoom extends StatefulWidget {
0 commit comments