getStats method

  1. @override
Future<CacheStats> getStats()
override

Gets cache usage statistics.

Returns information about hits, misses, size, etc.

Implementation

@override
Future<CacheStats> getStats() async {
  await _ensureInitialized();

  final totalSize = _metadataCache.values
      .map((entry) => entry.sizeInBytes)
      .fold(0, (sum, size) => sum + size);

  final expiredCount = _metadataCache.values
      .where((entry) => entry.isExpired)
      .length;

  return CacheStats(
    hits: _hits,
    misses: _misses,
    itemCount: _metadataCache.length,
    totalSizeInBytes: totalSize,
    expiredItems: expiredCount,
    statsStartTime: _stats.statsStartTime,
  );
}