preloadProxies method

Future<void> preloadProxies()

Preloads proxies into the cache

Implementation

Future<void> preloadProxies() async {
  if (_isPreloading) return;

  _isPreloading = true;

  try {
    // Fetch proxies from all sources
    final proxies = await _repository.fetchProxies(
      options: const ProxyFilterOptions(count: 100, onlyHttps: true),
    );

    // Convert to proxy models
    final proxyModels = proxies.whereType<ProxyModel>().toList();

    // Add to cache
    for (final proxy in proxyModels) {
      await _cacheManager.addProxy(proxy);
    }

    // Validate the proxies in the background
    validateCachedProxies();
  } finally {
    _isPreloading = false;
  }
}