Question:

How should I configure publishing on Sitecore 8.2+?

Benjamin: 5 days ago

What are the best practices for publishing configuration on Sitecore these days, especially given the performance improvements on 8.2 when using the new publishing service?

  • Scheduled incremental publishes?
  • Workflow based publishes?
  • Allow manual user publishes?
  • Something else?

This is a multi-site scenario that will have ongoing site builds even after initial launch. So content will be updated frequently. I would like to minimize HTML cache clears and as much as possible make it easy for authors to ensure they publish all needed items.

Answer:
Jack: 5 days ago

  • If your content authors are strictly following WorkFlow, use scheduled Incremental publishes.

  • If workflow is not strictly used, use user manual publishes (Smart Publish), and try to cover related item publishes to reduce number of cache clears.

  • For multisite, if you publish item of site-A. It will clear html cache for all sites. It should clear cache for site-A only.

For this, you must customize the publish:end:remote event. For that, find the root item got published (on CD server), identify which site the item related is, and clear HTML cache for that site only. This case is nicely explained in "Sitecore Cookbook for Developers" (http://rads.stackoverflow.com/amzn/click/1784396524). Still, here is the code for that (Add this processor to the event and replace existing one):

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);
 }

 private static void ClearHtmlCache(Item rootItem) {
  List<SiteInfo> sites = Factory.GetSiteInfoList();
  var selectedSites = sites
    .Where(s => rootItem.Paths.Path.ToLower().StartsWith(
     s.RootPath.ToLower()) && s.Database.ToLower() == "web");
  foreach(SiteInfo site in selectedSites) {
    ClearSiteHtmlCache(site);
  }
 }


 private static void ClearSiteHtmlCache(SiteInfo site) {
  string cacheName = site.Name + "[html]";
  Cache cache = CacheManager.FindCacheByName(cacheName);
  if (cache != null)
   cache.Clear();
 }