clearCache method

Future<void> clearCache()

Clear all cache

Deletes entire cache and all metadata.

Implementation

Future<void> clearCache() async {
  try {
    if (kDebugMode) {
      debugPrint('[WebCacheService] 🗑️ Clearing cache');
    }

    // Delete Cache API
    await _cacheInterop.deleteCache(cacheName);

    // Delete all metadata
    final prefs = _prefs;
    final keys = prefs.getKeys();
    for (final key in keys) {
      if (key.startsWith(PreferencesKeys.webCacheMetadataPrefix)) {
        await prefs.remove(key);
      }
    }

    if (kDebugMode) {
      debugPrint('[WebCacheService] ✅ Cache cleared');
    }
  } catch (e) {
    debugPrint('[WebCacheService] ❌ clearCache failed: $e');
    rethrow;
  }
}