using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using Sitecore.Web.UI.WebControls; namespace _071114 { public class MyCacheableControl : CachingEnabledControl { protected override void CreateChildControls() { if ( IsSitecoreCached ) return; Controls.Clear(); // This method gets executed every single time, regardless of whether or not Sitecore cache is output System.Threading.Thread.Sleep( 10000 ); Controls.Add( new LiteralControl( "Now: " + DateTime.Now.ToString() ) ); base.CreateChildControls(); } } public class CachingEnabledControl : System.Web.UI.Control { public bool IsSitecoreCached { get { Control c = Parent; while ( c != null && !(c is Sublayout) ) { c = c.Parent; if ( c == null ) break; } if ( c != null ) { Sublayout sl = c as Sublayout; if ( Sitecore.Caching.CacheManager.GetHtmlCache( Sitecore.Context.Site ).InnerCache.ContainsKey( sl.GetCacheKey() ) ) { return true; } } return false; } } } }