protected override void DoProcess(ClearOutputCachesArgs args)
        {
            if (args.OutputCacheClearingOptions.IgnorePublishingTargets ||
                args.OutputCacheClearingOptions.PublishingTargets == null ||
                args.OutputCacheClearingOptions.PublishingTargets.Count < 1)
            {
                Log.Info(this + " : IgnorePublishingTargets or PublishingTarget null or empty : return : " + args.OutputCacheClearingOptions.IgnorePublishingTargets + " : " + args.OutputCacheClearingOptions.PublishingTargets, this);
                return;
            }

            foreach (OutputCacheSite outputCacheSite
                     in args.OutputCacheSites.ToArray())
            {
                bool isRelevant = false;

                foreach (string target in args.OutputCacheClearingOptions.PublishingTargets)
                {
                    if (outputCacheSite.IsPublishingTargetRelevant(target))
                    {
                        isRelevant = true;
                        break;
                    }
                }

                if (!isRelevant)
                {
                    args.OutputCacheSites.Remove(outputCacheSite);
                }
            }
        }
        protected override void DoProcess(ClearOutputCachesArgs args)
        {
            foreach (SiteInfo siteInfo
                     in Sitecore.Configuration.Factory.GetSiteInfoList())
            {
//        Log.Info(this + " : checking siteInfo for " + siteInfo.Name, this);

                if (!siteInfo.CacheHtml)
                {
//          Log.Info(this + " : CacheHtml false; continue : " + siteInfo.Name, this);
                    continue;
                }

                SiteContext siteContext =
                    Sitecore.Configuration.Factory.GetSite(siteInfo.Name);
                Assert.IsNotNull(siteContext, "siteContext: " + siteInfo.Name);
                HtmlCache htmlCache = CacheManager.GetHtmlCache(siteContext);

                if (htmlCache == null ||
                    htmlCache.InnerCache.Count < 1 ||
                    (htmlCache.InnerCache.Count < 2 &&
                     htmlCache.InnerCache.ContainsKey(args.LastClearedKey)))
                {
                    Log.Info(this + " : no html cache, cache count less than one, or only contains last cleared key : " + siteInfo.Name + " : " + htmlCache, this);
                    continue;
                }

                Log.Info(this + " : AddOutputCacheSite! : " + siteInfo.Name, this);
                args.AddOutputCacheSite(new OutputCacheSite(
                                            siteContext,
                                            htmlCache,
                                            args.LastClearedKey));
            }
        }
        public void Process(ClearOutputCachesArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(
                args.OutputCacheSites,
                "args.OutputCacheSites");
            Log.Info(this + " : DoProcess()", this);
            this.DoProcess(args);

            if (args.OutputCacheSites.Count < 1)
            {
                Log.Info(this + " args.OutputCacheSites.Count < 1 : AbortPipeline()", this);
                args.AbortPipeline();
            }
        }
        protected override void DoProcess(ClearOutputCachesArgs args)
        {
            ScavengeOutputCacheKey.ScavengeOutputCacheKeyArgs innerArgs =
                new ScavengeOutputCacheKey.ScavengeOutputCacheKeyArgs(args);

            foreach (OutputCacheSite outputCacheSite in args.OutputCacheSites)
            {
                innerArgs.OutputCacheSite = outputCacheSite;

                foreach (string key in outputCacheSite.HtmlCache.InnerCache.GetCacheKeys())
                {
                    innerArgs.CacheKey = key;
                    CorePipeline.Run("scavengeOutputCacheKey", innerArgs);
                }
            }
        }
Пример #5
0
        protected override void DoProcess(ClearOutputCachesArgs args)
        {
            if (args.OutputCacheClearingOptions.IgnorePublishingLanguage ||
                string.IsNullOrEmpty(args.OutputCacheClearingOptions.PublishingLanguage))
            {
                Log.Info(this + " args.IgnorePublishingLanguage : " + args.OutputCacheClearingOptions.IgnorePublishingLanguage + " : return", this);
                return;
            }

            foreach (OutputCacheSite outputCacheSite
                     in args.OutputCacheSites.ToArray())
            {
                if (!outputCacheSite.IsLanguageRelevant(
                        args.OutputCacheClearingOptions.PublishingLanguage))
                {
                    Log.Info(this + " : " + outputCacheSite.SiteContext.Name + " not relevant to " + args.OutputCacheClearingOptions.PublishingLanguage + " : return", this);
                    args.RemoveOutputCacheSite(outputCacheSite);
                }
            }
        }
        protected override void DoProcess(ClearOutputCachesArgs args)
        {
            //TODO: for republish or when flags indicate, clear caches regardless

            if ((args.OutputCacheClearingOptions.CacheKeysMustContainOne != null &&
                 args.OutputCacheClearingOptions.CacheKeysMustContainOne.Count > 0) ||
                (args.OutputCacheClearingOptions.CacheKeysMustNotContainAny != null &&
                 args.OutputCacheClearingOptions.CacheKeysMustNotContainAny.Count > 0))
            {
                Log.Info(this + " : contains mismatch : return", this);
                return;
            }

            foreach (OutputCacheSite outputCacheSite in args.OutputCacheSites)
            {
                Log.Info(this + " : clear outut cache! for " + outputCacheSite.SiteContext.Name + " : " + Sitecore.DateUtil.IsoNow + " : " + DateUtil.ToIsoDate(DateTime.Now), this);
                outputCacheSite.HtmlCache.Clear();
                outputCacheSite.HtmlCache.SetHtml(
                    args.LastClearedKey,
                    DateUtil.ToIsoDate(DateTime.Now));
            }

            args.AbortPipeline();
        }
        protected override void DoProcess(ClearOutputCachesArgs args)
        {
            if (args.OutputCacheClearingOptions.IgnoreIntervals)
            {
                Log.Info(this + " : IgnoreIntervals.", this);
                return;
            }

            foreach (OutputCacheSite outputCacheSite in args.OutputCacheSites.ToArray())
            {
                if (!outputCacheSite.CacheHasExpired)
                {
                    //TODO: schedule cache clearing for last clearance time + interval
                    Log.Info(this + " : remove site " + outputCacheSite.SiteContext.Name + " because cache has not expired.", this);
                    args.RemoveOutputCacheSite(outputCacheSite);
                    Item command = outputCacheSite.SiteContext.Database.GetItem(
                        "/sitecore/system/Tasks/Commands/ProcessOutputCaches");
                    Item schedule = outputCacheSite.SiteContext.Database.GetItem(
                        "/sitecore/system/Tasks/Schedules");
                    Template template = TemplateManager.GetTemplate(
                        "User Defined/Tasks/Schedule/ProcessOutputCaches",
                        outputCacheSite.SiteContext.Database);

                    if (command == null ||
                        schedule == null ||
                        template == null ||
                        template.GetField("OutputCacheClearingOptions") == null ||
                        template.GetField("Auto Remove") == null ||
                        template.GetField("Command") == null ||
                        template.GetField("Instance") == null ||
                        template.GetField("Schedule") == null)
                    {
                        Log.Warn(this + " : template for scheduling cache clearing operations does not exist or does not contain the correct fields.", this);
                        return;
                    }

                    if (schedule.Axes.SelectSingleItem(
                            ".//*[@Instance='" + Sitecore.Configuration.Settings.InstanceName +
                            "' and @Command='" + command.ID + "']") != null)
                    {
                        Log.Info(this + " : cache clearing operation already scheduled for this instance.", this);
                        return;
                    }

                    //TODO: only create if no schedule for same command exists for instance
                    Item task = schedule.Add(
                        string.Join(
                            ".",
                            DateUtil.ToIsoDate(DateTime.Now),
                            Sitecore.Configuration.Settings.InstanceName,
                            new Random().Next()).Replace(":", "_").Replace("-", "_").Replace(".", "_"),
                        new TemplateID(template.ID));

                    using (new EditContext(task))
                    {
                        XmlSerializer serializer = new XmlSerializer(
                            args.OutputCacheClearingOptions.GetType());
                        StringWriter sw = new StringWriter();
                        serializer.Serialize(sw, args.OutputCacheClearingOptions);
                        task["OutputCacheClearingOptions"] = sw.ToString();
                        task["Command"]     = command.ID.ToString();
                        task["Auto Remove"] = "1";
                        task["Instance"]    = Sitecore.Configuration.Settings.InstanceName;
                        task["Schedule"]    = string.Join(
                            "|",
                            DateUtil.ToIsoDate(DateTime.MinValue).Substring(0, 8),
                            DateUtil.ToIsoDate(DateTime.MaxValue).Substring(0, 8),
                            "127",
                            "00:01:00");
                    }
                }
            }
        }
 protected abstract void DoProcess(ClearOutputCachesArgs args);