getAll method

  1. @override
Map<String, CacheEntry> getAll()
override

Returns all cache entries as a map.

Useful for:

  • Debugging and inspection
  • Bulk operations
  • Cache migration

Expired entries should be excluded from the result.

Implementation

@override
Map<String, CacheEntry> getAll() {
  final result = <String, CacheEntry>{};
  final expiredKeys = <String>[];

  for (final key in _storageBox.keys) {
    final json = _storageBox.get(key);
    if (json == null) continue;

    try {
      final entry = CacheEntry.fromJson(Map<String, dynamic>.from(json));

      if (entry.isExpired) {
        expiredKeys.add(key.toString());
      } else {
        result[key.toString()] = entry;
      }
    } on Exception catch (e, s) {
      log(
        'HiveCacheStore: Failed to deserialize cache entry for key "$key": $e',
        level: 900,
        stackTrace: s,
      );
      // If deserialization fails, mark for deletion
      expiredKeys.add(key.toString());
    }
  }

  // Clean up expired/corrupted entries
  expiredKeys.forEach(delete);

  return Map.unmodifiable(result);
}