reduceCacheSize function

Future<void> reduceCacheSize(
  1. ObjectBox objectBox,
  2. List<CachedImageInfo> allCachedImageInfo
)

Implementation

Future<void> reduceCacheSize(ObjectBox objectBox, List<CachedImageInfo> allCachedImageInfo) async {
  if (allCachedImageInfo.isNotEmpty) {
    allCachedImageInfo.sort((a, b) => a.dateCreated.compareTo(b.dateCreated));
    final a = allCachedImageInfo.first;
    if (getShowLogs) {
      developer.log("🧽 Clearing cache from ${a.cachedImageUrl}");
    }
    await deleteImageInCache(a.cachedImageUrl);
    removeCachedImageInfo(objectBox, a.id);
  }
}