Advertisement
Guest User

Untitled

a guest
May 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. public class HtmlCacheClearer : Sitecore.Publishing.HtmlCacheClearer
  2. {
  3. private const string SettingName = "CustomHtmlCacheClearer.IgnoreItems";
  4.  
  5. public new void ClearCache(object sender, EventArgs args)
  6. {
  7. if (sender == null)
  8. {
  9. return;
  10. }
  11.  
  12. var sitecoreEventArgs = args as SitecoreEventArgs;
  13. if (sitecoreEventArgs == null || !sitecoreEventArgs.Parameters.Any())
  14. {
  15. return;
  16. }
  17.  
  18. var publisher = sitecoreEventArgs.Parameters[0] as Publisher;
  19. if (publisher == null)
  20. {
  21. return;
  22. }
  23.  
  24. if (IsCacheClearRequired(publisher.Options))
  25. {
  26. base.ClearCache(sender, args);
  27. }
  28. }
  29.  
  30. protected bool IsCacheClearRequired(PublishOptions publishOptions)
  31. {
  32. var exemptPaths = Sitecore.Configuration.Settings.GetSetting(SettingName);
  33. if (string.IsNullOrWhiteSpace(exemptPaths))
  34. {
  35. return true;
  36. }
  37.  
  38. return exemptPaths.Split('|')
  39. .All(excemptPath => !publishOptions.RootItem.Paths.FullPath.StartsWith(excemptPath,StringComparison.OrdinalIgnoreCase));
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement