stats method

Future<({int bytes, int entries})> stats()

Returns the number of cached entries and their total size in bytes.

Implementation

Future<({int entries, int bytes})> stats() async {
  final dir = Directory(_dir);
  if (!await dir.exists()) return (entries: 0, bytes: 0);
  var count = 0;
  var bytes = 0;
  await for (final f in dir.list()) {
    if (f is File && f.path.endsWith('.json')) {
      count++;
      bytes += await f.length();
    }
  }
  return (entries: count, bytes: bytes);
}