getCacheInfo method
Implementation
Future<CacheInfo> getCacheInfo() async {
try {
final tmp = await getTemporaryDirectory();
final directory = Directory('${tmp.path}/$_cacheKey');
if (!directory.existsSync()) {
return const CacheInfo(fileCount: 0, totalSize: 0, files: []);
}
int totalSize = 0;
int fileCount = 0;
await for (final entity in directory.list(recursive: true, followLinks: false)) {
if (entity is File) {
try {
final stat = await entity.stat();
totalSize += stat.size;
fileCount++;
} catch (_) {}
}
}
return CacheInfo(fileCount: fileCount, totalSize: totalSize, files: const []);
} catch (e) {
return const CacheInfo(fileCount: 0, totalSize: 0, files: []);
}
}