Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
739 stars 427 forks source link

CacheManager saves files with the same path #397

Open nikitahummus opened 1 year ago

nikitahummus commented 1 year ago

🐛 Bug Report

Scheduled file cleanup on CachedNetworkImage throws FileSystemException: Cannot delete file. Issue After research, it turned out that different images are recorded along the same path. This happens because relativePath encoding uses Uuid().v1() , which uses DateTime.now() , which causes our error when loading a lot of files at the same time.

To solve this problem, changing the path encoding in _flutter_cache_manager-3.3.0/lib/src/cachemanager.dart putFile and putFileStream should help. for example, change v1 to v4, which uses a more random encoding

> cacheObject ??= CacheObject(
>       url,
>       key: key,
>       relativePath: '${const Uuid().v1()}.$fileExtension', 
>       validTill: DateTime.now().add(maxAge),
>     );
zhancheng commented 1 year ago

i have tried but not useful @nikitahummus

nikitahummus commented 1 year ago

I also moved the creation of Uuid() to the final variable and use the same object inside CacheObject when creating the path of it. And I did the same with the CacheManager in CachedNetworkImage, created CacheManager in static property of class with an image widget and use it without creating a new one each time.

it helped @zhancheng

https://github.com/Daegalus/dart-uuid/issues/43