getSize method
Gets the size of the cache
Implementation
Future<Map<CacheLevel, int>> getSize() async {
await _ensureInitialized();
final sizes = <CacheLevel, int>{};
// Get memory cache size
sizes[CacheLevel.memory] = _memoryCacheSize;
// Get disk cache size
int diskSize = 0;
if (await _diskCacheDir.exists()) {
final files = await _diskCacheDir.list().toList();
for (final file in files) {
if (file is File) {
final stat = await file.stat();
diskSize += stat.size;
}
}
}
sizes[CacheLevel.disk] = diskSize;
return sizes;
}