getCacheSize static method

Future<int> getCacheSize()

Get cache size in bytes

Implementation

static Future<int> getCacheSize() async {
  _ensureInitialized();

  int totalSize = 0;

  // Calculate SharedPreferences size
  final keys = _prefs!.getKeys();
  for (final key in keys) {
    final value = _prefs!.getString(key);
    if (value != null) {
      totalSize += value.length;
    }
  }

  // Calculate file cache size
  if (await _cacheDir!.exists()) {
    await for (final entity in _cacheDir!.list()) {
      if (entity is File) {
        totalSize += await entity.length();
      }
    }
  }

  return totalSize;
}