protected void PurgeCloudflareCache(IPublishingStrategy strategy, PublishEventArgs <IContent> e)
        {
            var umbracoFlareConfigModel = _configurationService.LoadConfigurationFile();

            if (!umbracoFlareConfigModel.PurgeCacheOn)
            {
                return;
            }

            var urls          = new List <string>();
            var currentDomain = UmbracoFlareUrlHelper.GetCurrentDomain();

            foreach (var content in e.PublishedEntities)
            {
                if (content.GetValue <bool>(ApplicationConstants.UmbracoFlareBackendProperties.CloudflareDisabledOnPublishPropertyAlias))
                {
                    continue;
                }

                urls.AddRange(_umbracoFlareDomainService.GetUrlsForNode(content.Id, currentDomain));
            }

            var result = _cloudflareService.PurgePages(urls);

            e.Messages.Add(result.Success
                ? new EventMessage(ApplicationConstants.EventMessageCategory.CloudflareCaching,
                                   "Successfully purged the cloudflare cache.", EventMessageType.Success)
                : new EventMessage(ApplicationConstants.EventMessageCategory.CloudflareCaching,
                                   "We could not purge the Cloudflare cache. Please check the logs to find out more.",
                                   EventMessageType.Warning));
        }
Exemple #2
0
        public StatusWithMessage PurgeCacheForContentNode([FromBody] PurgeFromContentTree model)
        {
            if (model.NodeId <= 0)
            {
                return(new StatusWithMessage(false, "You must provide a node id."));
            }

            var currentDomainIsValid = _umbracoFlareDomainService.GetAllowedCloudflareDomains().Count(x => x.Equals(model.CurrentDomain)) > 0;

            if (!currentDomainIsValid)
            {
                return(new StatusWithMessage(false, "The current domain is not valid, please check if the domain is a valid zone in your cloudflare account " +
                                             "and make sure you this account is associated in the umbracoflare dashboard"));
            }

            var urls = new List <string>();

            urls.AddRange(_umbracoFlareDomainService.GetUrlsForNode(model.NodeId, model.CurrentDomain, model.PurgeChildren));

            var result = _cloudflareService.PurgePages(urls);

            return(!result.Success ? result : new StatusWithMessage(true, $"{urls.Count()} urls purged successfully."));
        }