emptyCache() does not work anymore
I use 3.4.1.
I work with
await cacheManager.downloadFile(url);
and after that I get it from the cache with:
final fileInfo = await cacheManager.getFileFromCache(
url,
);
I try to delete the cache with
await cacheManager.emptyCache();
It was working for a long time but now it is not working anymore.
flutter 3.29.3
I have got same issue void _clearCache() async{ DefaultCacheManager().emptyCache(); setState(() { fileStream = null; }); } It is not remove cache
(running Flutter 3.32.8, flutter_cache_manager: ^3.4.1 on a MacOS) Just a quick check it seems like:
cache_store.dart > class CacheStore
_Future
though the absolute path of the file is wrong showing this:
"/Users/
So line 187 final file = io.File(cacheObject.relativePath); points to a non existing file and line 189 if (file.existsSync()) always fails.
This creates a secondary defect as now files will be re-downloaded and duplicated in disk.
For a potential fix, you might want to look into this PR: https://github.com/Baseflow/flutter_cache_manager/pull/477/commits/3d1995f175087475e6c2d8f78fd59a0683e773f7
@hafizramiz
I have temporarily solved it manually until the plugin developer addresses the problem:
Future<void> clearCachePhysically() async {
final baseDir = await getTemporaryDirectory();
final cacheDir = Directory('${baseDir.path}/libCachedImageData');
if (await cacheDir.exists()) {
await cacheDir.delete(recursive: true);
print("Cache deleted.");
}
}