コード例 #1
0
        private void OnPublishEndRemoteHandled(object sender, EventArgs args)
        {
            PublishEndRemoteEventArgs remoteArgs = args as PublishEndRemoteEventArgs;

            bool deep       = remoteArgs.Deep;
            ID   rootItemID = ID.Parse(remoteArgs.RootItemId);

            // We can't rely on the name of the target database (as the publishing target name in the CM may not match a DB name in the CD environment)
            // Iterate over each supported DB and try to get the item
            foreach (string db in SupportedDatabaseNames)
            {
                Database publishingTarget = Sitecore.Configuration.Factory.GetDatabase(db);
                if (publishingTarget != null)
                {
                    Item publishedItem = publishingTarget.GetItem(rootItemID);

                    if (publishedItem != null)
                    {
                        if (deep)
                        {
                            Cache.RemoveTree(publishedItem);
                        }
                        else
                        {
                            Cache.RemoveItem(publishedItem);
                        }
                    }
                }
            }
        }
コード例 #2
0
        private static IEnumerable <Item> ClearByOption(PublishEndRemoteEventArgs option)
        {
            var database = Factory.GetDatabase(option.SourceDatabaseName);

            var item = database.GetItem(new ID(option.RootItemId));

            return(ExtractPublishItems(item, option.Deep));
        }
コード例 #3
0
        protected void ClearCache(object Sender, EventArgs args)
        {
            PublishEndRemoteEventArgs pubArgs = (PublishEndRemoteEventArgs)args;
            string rootID = pubArgs.RootItemId.ToString();

            Database db       = Database.GetDatabase(pubArgs.TargetDatabaseName);
            Item     rootItem = db.GetItem(rootID);

            if (rootItem != null)
            {
                ClearHtmlCache(rootItem);
            }
        }
コード例 #4
0
        protected virtual IEnumerable <SiteContext> GetSitesAffectedByPublish(PublishEndRemoteEventArgs args)
        {
            var targetDb  = string.IsNullOrWhiteSpace(args.TargetDatabaseName) ? null : Factory.GetDatabase(args.TargetDatabaseName);
            var siteNames = Sites.Count > 0 ? Sites.Cast <string>().ToArray() : Factory.GetSiteNames();
            var sites     = siteNames.Select(Factory.GetSite).Where(x => x != null);

            var  rootItemId = new ID(args.RootItemId);
            Item rootItem   = null;

            if (targetDb != null && !ID.IsNullOrEmpty(rootItemId))
            {
                rootItem = targetDb.GetItem(rootItemId);
            }
            if (rootItem == null)
            {
                Log.Info(this + " : There is no root item for publish action. This will result in more aggressive cache clearing.", this);
            }
            else if (!rootItem.Paths.Path.ToLowerInvariant().StartsWith("/sitecore/content/"))
            {
                Log.Info(this + " : Publish root is not under the content tree. Cache clearing will not consider publish root when filtering sites.", this);
                rootItem = null;
            }

            foreach (var site in sites)
            {
                if (!site.CacheHtml)
                {
                    Log.Debug(this + " : output caching not enabled for " + site.Name, this);
                    continue;
                }
                if (targetDb != null && site.Database != null && targetDb.Name != site.Database.Name)
                {
                    Log.Debug(this + " : " + targetDb + " not relevent to " + site.Name, this);
                    continue;
                }
                if (rootItem != null && !rootItem.Paths.FullPath.StartsWith(site.RootPath, StringComparison.CurrentCultureIgnoreCase))
                {
                    Log.Debug(this + " : " + site.Name + " does not contain publish root item.", this);
                    continue;
                }
                yield return(site);
            }
        }