@Override
  public boolean invalidateIfNecessary(BaragonRequest request) {
    if (request.getLoadBalancerService().getEdgeCacheDomains().isEmpty()) {
      return false;
    }

    try {
      boolean allSucceeded = true;
      for (String edgeCacheDNS : request.getLoadBalancerService().getEdgeCacheDomains()) {
        List<CloudflareZone> matchingZones = getCloudflareZone(edgeCacheDNS);

        if (matchingZones.isEmpty()) {
          LOG.warn("`edgeCacheDNS` was defined on the request, but no matching Cloudflare Zone was found!");
          return false;
        }

        for (CloudflareZone matchingZone : matchingZones) {
          String zoneId = matchingZone.getId();
          Optional<CloudflareDnsRecord> matchingDnsRecord = getCloudflareDnsRecord(edgeCacheDNS, zoneId);

          if (!matchingDnsRecord.isPresent()) {
            LOG.warn("`edgeCacheDNS` was defined on the request, but no matching Cloudflare DNS Record was found!");
            return false;
          }

          if (!matchingDnsRecord.get().isProxied()) {
            LOG.warn("`edgeCacheDNS` was defined on the request, but {} is not a proxied DNS record!", edgeCacheDNS);
            return false;
          }

          String cacheTag = String.format(
              edgeCacheConfiguration.getIntegrationSettings().get("cacheTagFormat"),
              request.getLoadBalancerService().getServiceId()
          );

          LOG.debug("Sending cache purge request against {} for {} to Cloudflare...", matchingDnsRecord.get().getName(), cacheTag);

          allSucceeded = cf.purgeEdgeCache(zoneId, Collections.singletonList(cacheTag)) && allSucceeded;
        }
      }
      return allSucceeded;

    } catch (CloudflareClientException e) {
      LOG.error("Unable to invalidate Cloudflare cache for request {}", request, e);
      return false;
    }
  }
@Override
  public boolean invalidateIfNecessary(BaragonRequest request) {
    if (request.getLoadBalancerService().getEdgeCacheDomains().isEmpty()) {
      return false;
    }

    try {
      boolean allSucceeded = true;
      for (String edgeCacheDNS : request.getLoadBalancerService().getEdgeCacheDomains()) {
        List<CloudflareZone> matchingZones = getCloudflareZone(edgeCacheDNS);

        if (matchingZones.isEmpty()) {
          LOG.warn("`edgeCacheDNS` was defined on the request, but no matching Cloudflare Zone was found!");
          return false;
        }

        for (CloudflareZone matchingZone : matchingZones) {
          String zoneId = matchingZone.getId();
          Optional<CloudflareDnsRecord> matchingDnsRecord = getCloudflareDnsRecord(edgeCacheDNS, zoneId);

          if (!matchingDnsRecord.isPresent()) {
            LOG.warn("`edgeCacheDNS` was defined on the request, but no matching Cloudflare DNS Record was found!");
            return false;
          }

          if (!matchingDnsRecord.get().isProxied()) {
            LOG.warn("`edgeCacheDNS` was defined on the request, but {} is not a proxied DNS record!", edgeCacheDNS);
            return false;
          }

          String cacheTag = String.format(
              edgeCacheConfiguration.getIntegrationSettings().get("cacheTagFormat"),
              request.getLoadBalancerService().getServiceId()
          );

          LOG.debug("Sending cache purge request against {} for {} to Cloudflare...", matchingDnsRecord.get().getName(), cacheTag);

          allSucceeded = cf.purgeEdgeCache(zoneId, Collections.singletonList(cacheTag)) && allSucceeded;
        }
      }
      return allSucceeded;

    } catch (CloudflareClientException e) {
      LOG.error("Unable to invalidate Cloudflare cache for request {}", request, e);
      return false;
    }
  }
@ Override public boolean invalidateIfNecessary ( BaragonRequest request ) { if ( request . getLoadBalancerService ( ) . getEdgeCacheDomains ( ) . isEmpty ( ) ) { return false ; } try { boolean allSucceeded = true ; for ( String edgeCacheDNS : request . getLoadBalancerService ( ) . getEdgeCacheDomains ( ) ) { List < CloudflareZone > matchingZones = getCloudflareZone ( edgeCacheDNS ) ; if ( matchingZones . isEmpty ( ) ) { LOG . warn ( "`edgeCacheDNS` was defined on the request, but no matching Cloudflare Zone was found!" ) ; return false ; } for ( CloudflareZone matchingZone : matchingZones ) { String zoneId = matchingZone . getId ( ) ; Optional < CloudflareDnsRecord > matchingDnsRecord = getCloudflareDnsRecord ( edgeCacheDNS , zoneId ) ; if ( ! matchingDnsRecord . isPresent ( ) ) { LOG . warn ( "`edgeCacheDNS` was defined on the request, but no matching Cloudflare DNS Record was found!" ) ; return false ; } if ( ! matchingDnsRecord . get ( ) . isProxied ( ) ) { LOG . warn ( "`edgeCacheDNS` was defined on the request, but {} is not a proxied DNS record!" , edgeCacheDNS ) ; return false ; } String cacheTag = String . format ( edgeCacheConfiguration . getIntegrationSettings ( ) . get ( "cacheTagFormat" ) , request . getLoadBalancerService ( ) . getServiceId ( ) ) ; LOG . debug ( "Sending cache purge request against {} for {} to Cloudflare..." , matchingDnsRecord . get ( ) . getName ( ) , cacheTag ) ; allSucceeded = cf . purgeEdgeCache ( zoneId , Collections . singletonList ( cacheTag ) ) && allSucceeded ; } } return allSucceeded ; } catch ( CloudflareClientException e ) { LOG . error ( "Unable to invalidate Cloudflare cache for request {}" , request , e ) ; return false ; } }
Invalidation will eventually occur when the TTL expires, so it's not a showstopper if this fails.
Invalidation will eventually occur when the TTL expires so it s not a showstopper if this fails .